pax_global_header00006660000000000000000000000064133456756700014532gustar00rootroot0000000000000052 comment=5d5c7f853ac1a3ee3e8119f4e9d72b69cbb7812a ruby-xdg-2.2.3/000077500000000000000000000000001334567567000132775ustar00rootroot00000000000000ruby-xdg-2.2.3/.index000066400000000000000000000020561334567567000144120ustar00rootroot00000000000000--- type: ruby revision: 2013 sources: - Index.yml authors: - name: Trans email: transfire@gmail.com organizations: - name: Rubyworks requirements: - groups: - build development: true name: detroit - groups: - test development: true name: qed - groups: - test development: true name: ae conflicts: [] alternatives: [] resources: - type: home uri: http://rubyworks.github.com/xdg label: Homepage - type: code uri: http://github.com/rubyworks/xdg label: Source Code - type: mail uri: http://groups.goole.com/rubyworks-mailinglist label: Mailing List repositories: - name: upstream scm: git uri: git://github.com/rubyworks/xdg.git categories: [] load_path: - lib copyrights: - holder: Rubyworks year: '2008' license: BSD-2-Clause name: xdg title: XDG version: 2.2.3 summary: XDG provides an interface for using XDG directory standard. description: XDG provides a module for supporting the XDG Base Directory Standard. See http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html created: '2008-09-27' date: '2012-12-12' ruby-xdg-2.2.3/.yardopts000066400000000000000000000001401334567567000151400ustar00rootroot00000000000000--title "YARD-Bird" --readme README.md --output-dir site/doc --private lib/**/*.rb - *.md *.txt ruby-xdg-2.2.3/DEMO.md000066400000000000000000000075361334567567000143600ustar00rootroot00000000000000# XDG Base Directory Standard The 2.0 API is much a great deal more concise than the original 0.0+ and 1.0+ APIs. It consists primarily of a single interface method `XDG[]`. Yet all the functionality of the older API remain and then some. First we need to require the library. require 'xdg' In the applique we have setup a fake root directory with coorepsonding environment settings to use as test fixtures. ## Data Paths ### Home XDG['DATA_HOME'].environment.assert == ENV['XDG_DATA_HOME'].to_s XDG['DATA_HOME'].environment_variables.assert == ['XDG_DATA_HOME'] Looking at the data home location by default it should be point to our joe user's home directory under `.local/share`. XDG['DATA_HOME'].to_a.assert == [$froot + 'home/joe/.local/share'] ### Dirs XDG['DATA_DIRS'].environment.assert == ENV['XDG_DATA_DIRS'].to_s XDG['DATA_DIRS'].environment_variables.assert == ['XDG_DATA_DIRS'] Looking at the system data locations XDG['DATA_DIRS'].to_a.assert == [$froot + 'usr/share'] ### Combined XDG['DATA'].environment_variables.assert == ['XDG_DATA_HOME', 'XDG_DATA_DIRS'] Lookking at both data location combined XDG['DATA'].to_a.assert == [$froot + 'home/joe/.local/share', $froot + 'usr/share'] ## Config Paths ### Home XDG['CONFIG_HOME'].environment.assert == ENV['XDG_CONFIG_HOME'].to_s XDG['CONFIG_HOME'].to_a.assert == [$froot + 'home/joe/.config'] ### Dirs XDG['CONFIG_DIRS'].environment.assert == ENV['XDG_CONFIG_DIRS'].to_s XDG['CONFIG_DIRS'].to_a.assert == [$froot + 'etc/xdg', $froot + 'etc'] ### Combined XDG['CONFIG'].to_a.assert == [$froot + 'home/joe/.config', $froot + 'etc/xdg', $froot + 'etc'] ## Cache Paths ### Home XDG['CACHE_HOME'].environment.assert == ENV['XDG_CACHE_HOME'].to_s XDG['CACHE_HOME'].to_a.assert == [$froot + 'home/joe/.cache'] ### Dirs XDG['CACHE_DIRS'].environment.assert == ENV['XDG_CACHE_DIRS'].to_s XDG['CACHE_DIRS'].to_a.assert == [$froot + 'tmp'] ### Combined XDG['CACHE'].to_a.assert == [$froot + 'home/joe/.cache', $froot + 'tmp'] # Extended Base Directory Standard The extended base directory standard provides additional locations not apart the offical standard. These are somewhat experimental. ## Resource XDG['RESOURCE_HOME'].environment.assert == ENV['XDG_RESOURCE_HOME'].to_s XDG['RESOURCE_HOME'].environment_variables.assert == ['XDG_RESOURCE_HOME'] Looking at the data home location by default it should be pointing to our joe users home directory under `.local`. XDG['RESOURCE_HOME'].list.assert == ['~/.local'] XDG['RESOURCE_HOME'].to_a.assert == [$froot + 'home/joe/.local'] ## Work The working configuration directory XDG['CONFIG_WORK'].environment.assert == ENV['XDG_CONFIG_WORK'].to_s XDG['CONFIG_WORK'].environment_variables.assert == ['XDG_CONFIG_WORK'] Looking at the config work location, by default it should be pointing to the current working directorys `.config` or `config` directory. XDG['CONFIG_WORK'].list.assert == ['.config', 'config'] XDG['CONFIG_WORK'].to_a.assert == [Dir.pwd + '/.config', Dir.pwd + '/config'] The working cache directory XDG['CACHE_WORK'].environment.assert == ENV['XDG_CACHE_WORK'].to_s XDG['CACHE_WORK'].environment_variables.assert == ['XDG_CACHE_WORK'] Looking at the cache work location, by default it should be pointing to the current working directorys `.tmp` or `tmp` directory. XDG['CACHE_WORK'].list.assert == ['.tmp', 'tmp'] XDG['CACHE_WORK'].to_a.assert == [Dir.pwd + '/.tmp', Dir.pwd + '/tmp'] # Base Directory Mixin The base directory mixin is used to easy augment a class for access to a named subdirectory of the XDG directories. class MyAppConfig include XDG::BaseDir::Mixin def subdirectory 'myapp' end end c = MyAppConfig.new c.config.home.to_a #=> [$froot + 'home/joe/.config/myapp'] ruby-xdg-2.2.3/HISTORY.md000066400000000000000000000066401334567567000147700ustar00rootroot00000000000000# RELEASE HISTORY ## 2.2.3 / 2012-12-13 This release switches to RbConfig instead of Config, which Ruby is deprecating. Changes: * Switch Config to RbConfig. ## 2.2.2 / 2011-10-30 Just a maintenance release to bring the build configuration up to date. Also, change license to BSD-2-Clause. Changes: * Modernize build configuration * Switch to BSD-2-Clause license. ## 2.2.1 / 2011-06-11 This release changes BaseDir#to_s to return the first directory entry, and moves the old #to_s to #environment_with_defaults with an alias of #env. The old #env now being called #environment. Changes: * Rename #env to #environment. * Rename #to_s to #environment_with_defaults. * Modify #to_s to return first directory. ## 2.1.0 / 2011-06-09 This release changes the BaseDir#list method, where as it used to be an alias for #to_a, it now differs in that it does not expand the paths. In addtion a few tests were fixed and version number properly updated int hte version.rb file. Changes: * Change BaseDir#list to not expand paths. * Properly assign VERSION constant. * Fix broken qed tests. ## 2.0.0 / 2011-06-09 Major new release is full rewrite of the API, with an eye out for support future XDG standards beyond the base directories. The new API uses a single point of entry `XDG[]` (a shortcut for `XDG::BaseDir[]`). Changes: * Complete rewrite of API. * Utilize single point of entry interface. * Structure project for future support of more of XDG. ## 1.0.0 / 2009-12-01 This is major reimplementation of the XDG API to be more flexiable and object-oriented. Instead of a single module with every needed method, the system is devided up into sub-modules, one for each set of XDG locations. So, for example, instead of "XDG.data_dirs" you use "XDG::Data.dirs" or "XDG.data.dirs". Changes: * Reworked API and underlying implementation to be more OOP-style. * Began work on xdg/extended.rb, exploring future proposals. * Provides xdg/compat.rb, for backward compatabilty (temporary). ## 0.5.2 / 2009-05-30 This release requires rbconfig.rb and uses system entries in place of some hardcoded FHS locations. Changes: * Replaced hardcoded system directories with rbconfig entries. ## 0.5.1 / 2008-11-17 Changes: * Fixed data work directory is '.local', not '.share' * Deprecated #data_work ## 0.5.0 / 2008-10-28 Changes: * Changed _glob to _select ## 0.4.0 / 2008-10-26 This release removes the xdg_ prefix from the instance-level method names. Now module and instance levels are the same. Also, data_file, config_file and cache_file have been replaced with data_find, config_find, cache_find, data_glob, config_glob and cache_glob. What's next? Well, I can't say I'm fond of the term 'glob', so I may rename that to 'map' or 'collect' (or 'select'?) and then add the ability to use blocks for matching too. Changes: * Renamed instance level methods without 'xdg_' prefix. * Replace _file methods with _find and _glob methods. * Prepare for v0.4 release * Remove some old commented-out code * Fixed data_find and data_glob * Update RELEASE file * Updated documentation for 0.4 release * Added MANIFEST to .gitignore * Correction or RELEASE * Fixed plural in RELEASE file ## 0.3.0 / 2008-10-11 Changes: * Removed xdg_ prefix from module methods * Moved web/index.html to doc directory * Updated reap serives * Prepare for next release * Fixed issue of xdg_ prefix still being used internally ## 0.1.0 / 2008-09-27 Changes: * Started project ruby-xdg-2.2.3/LICENSE.txt000066400000000000000000000023351334567567000151250ustar00rootroot00000000000000BSD-2-Clause License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ruby-xdg-2.2.3/README.md000066400000000000000000000075511334567567000145660ustar00rootroot00000000000000# XDG Standards for Ruby [Homepage](http://rubyworks.github.com/xdg) | [Source Code](http://github.com/rubyworks/xdg) | [Report Issue](http://github.com/rubyworks/xdg/issues) | [Mailing List](http://googlegroups.com/group.rubyworks-mailinglist) | [Chat Room](irc://irc.freenode.net/rubyworks) [![Build Status](https://secure.travis-ci.org/rubyworks/xdg.png)](http://travis-ci.org/rubyworks/xdg) ## Introduction XDG provides an easy to use Ruby library for working with XDG standards. Presently, it only supports the XDG Base Directory Standard. If your program utilizes user or system-wide support files (e.g. configuration files), you owe it to yourself to checkout the XDG base directory standard. You can learn more about the standard at: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html ## How to Use For working with XDG base directories, XDG provides a very simple yet flexible interface, `XDG[]`. Let's say you want to work with the $XDG_CONFIG_HOME directory. Simply use: XDG['CONFIG_HOME'] This will give you access to a number of useful methods all tied into the user's personal configuration directory. Some examples: XDG['CONFIG_HOME'].glob(pattern) XDG['CONFIG_HOME'].select(pattern){ |path| ... } XDG['CONFIG_HOME'].find(pattern){ |path| ... } The same holds true for the other base directories. XDG['DATA_HOME'] XDG['DATA_DIRS'] XDG['CACHE_HOME'] XDG['CACHE_DIRS'] By leaving out the last qualifier, XDG will provide an interface that ties into both the `HOME` and `DIRS` paths. XDG['DATA'] XDG['CONFIG'] XDG['CACHE'] If you know XDG these are pretty much self-explanatory. But see the YARD-based API documentation for further specifics. ### Extended Functionality The Ruby XDG module also provides extended functionality not part of the standard specification. These extensions are simply add-on functionality deemed useful, or implementations of proposals being discussed for a possible future version of the standard. XDG['CONFIG_WORK'] XDG['CACHE_WORK'] See the API documentation to learn more. Note that the extended modules are subject to greater potential for change as they are still being refined. ### Base Directory Mixin XDG provides a convenient base directory mixin that can provide handy a interface to a classes. class MyAppConfig include XDG::BaseDir::Mixin def subdirectory 'myapp' end end c = MyAppConfig.new c.config.home.to_s #=> '~/.config/myapp' ### Legacy API Version 2.0+ of library marks a major departure from the earlier "fluid" notation of previous releases. Where as one used to do: XDG.data.home With the new API one now does: XDG['DATA_HOME'] This was done for a few reasons, but primarily because it reflects more closely Ruby's interface to the environment variables themselves, e.g. ENV['XDG_DATA_HOME'] If you prefer the older style, a compatibility layer is provided. You will need to load: require 'xdg/base_dir/legacy' However we STRONGLY RECOMMEND that you do not use the legacy API --use it only if you need to keep some old code working and don't have time to update it at the moment. Sometime in the future the legacy API will be deprecated. ## How to Install Using RubyGems: $ sudo gem install xdg Installing the tarball requires Ruby Setup (see http://rubyworks.github.com/setup). $ tar -xvzf xdg-0.5.2 $ cd xdg-0.5.2 $ sudo setup.rb all ## Development [GitHub](http://github.com) hosts our [source code](http://github.com/rubyworks/xdg) and [issue ticket system](http://github.com/rubyworks/xdg/issues). To contribute to the project please fork the repository, ideally, create a new topic branch for your work, and submit a pull request. ## Copyright & License Copyright (c) 2008 Rubyworks Distributed under the terms of the *FreeBSD* license. See LICENSE.txt file for details. ruby-xdg-2.2.3/demo/000077500000000000000000000000001334567567000142235ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/01_base_dir.md000066400000000000000000000040511334567567000166150ustar00rootroot00000000000000# XDG Base Directory Standard The 2.0 API is much a great deal more concise than the original 0.0+ and 1.0+ APIs. It consists primarily of a single interface method `XDG[]`. Yet all the functionality of the older API remain and then some. First we need to require the library. require 'xdg' In the applique we have setup a fake root directory with coorepsonding environment settings to use as test fixtures. ## Data Paths ### Home XDG['DATA_HOME'].environment.assert == ENV['XDG_DATA_HOME'].to_s XDG['DATA_HOME'].environment_variables.assert == ['XDG_DATA_HOME'] Looking at the data home location by default it should be point to our joe user's home directory under `.local/share`. XDG['DATA_HOME'].to_a.assert == [$froot + 'home/joe/.local/share'] ### Dirs XDG['DATA_DIRS'].environment.assert == ENV['XDG_DATA_DIRS'].to_s XDG['DATA_DIRS'].environment_variables.assert == ['XDG_DATA_DIRS'] Looking at the system data locations XDG['DATA_DIRS'].to_a.assert == [$froot + 'usr/share'] ### Combined XDG['DATA'].environment_variables.assert == ['XDG_DATA_HOME', 'XDG_DATA_DIRS'] Lookking at both data location combined XDG['DATA'].to_a.assert == [$froot + 'home/joe/.local/share', $froot + 'usr/share'] ## Config Paths ### Home XDG['CONFIG_HOME'].environment.assert == ENV['XDG_CONFIG_HOME'].to_s XDG['CONFIG_HOME'].to_a.assert == [$froot + 'home/joe/.config'] ### Dirs XDG['CONFIG_DIRS'].environment.assert == ENV['XDG_CONFIG_DIRS'].to_s XDG['CONFIG_DIRS'].to_a.assert == [$froot + 'etc/xdg', $froot + 'etc'] ### Combined XDG['CONFIG'].to_a.assert == [$froot + 'home/joe/.config', $froot + 'etc/xdg', $froot + 'etc'] ## Cache Paths ### Home XDG['CACHE_HOME'].environment.assert == ENV['XDG_CACHE_HOME'].to_s XDG['CACHE_HOME'].to_a.assert == [$froot + 'home/joe/.cache'] ### Dirs XDG['CACHE_DIRS'].environment.assert == ENV['XDG_CACHE_DIRS'].to_s XDG['CACHE_DIRS'].to_a.assert == [$froot + 'tmp'] ### Combined XDG['CACHE'].to_a.assert == [$froot + 'home/joe/.cache', $froot + 'tmp'] ruby-xdg-2.2.3/demo/02_base_dir_extended.md000066400000000000000000000027271334567567000205060ustar00rootroot00000000000000# Extended Base Directory Standard The extended base directory standard provides additional locations not apart the offical standard. These are somewhat experimental. ## Resource XDG['RESOURCE_HOME'].environment.assert == ENV['XDG_RESOURCE_HOME'].to_s XDG['RESOURCE_HOME'].environment_variables.assert == ['XDG_RESOURCE_HOME'] Looking at the data home location by default it should be pointing to our joe users home directory under `.local`. XDG['RESOURCE_HOME'].list.assert == ['~/.local'] XDG['RESOURCE_HOME'].to_a.assert == [$froot + 'home/joe/.local'] ## Work The working configuration directory XDG['CONFIG_WORK'].environment.assert == ENV['XDG_CONFIG_WORK'].to_s XDG['CONFIG_WORK'].environment_variables.assert == ['XDG_CONFIG_WORK'] Looking at the config work location, by default it should be pointing to the current working directorys `.config` or `config` directory. XDG['CONFIG_WORK'].list.assert == ['.config', 'config'] XDG['CONFIG_WORK'].to_a.assert == [Dir.pwd + '/.config', Dir.pwd + '/config'] The working cache directory XDG['CACHE_WORK'].environment.assert == ENV['XDG_CACHE_WORK'].to_s XDG['CACHE_WORK'].environment_variables.assert == ['XDG_CACHE_WORK'] Looking at the cache work location, by default it should be pointing to the current working directorys `.tmp` or `tmp` directory. XDG['CACHE_WORK'].list.assert == ['.tmp', 'tmp'] XDG['CACHE_WORK'].to_a.assert == [Dir.pwd + '/.tmp', Dir.pwd + '/tmp'] ruby-xdg-2.2.3/demo/03_base_dir_mixin.md000066400000000000000000000005331334567567000200240ustar00rootroot00000000000000# Base Directory Mixin The base directory mixin is used to easy augment a class for access to a named subdirectory of the XDG directories. class MyAppConfig include XDG::BaseDir::Mixin def subdirectory 'myapp' end end c = MyAppConfig.new c.config.home.to_a #=> [$froot + 'home/joe/.config/myapp'] ruby-xdg-2.2.3/demo/applique/000077500000000000000000000000001334567567000160435ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/applique/ae.rb000066400000000000000000000000351334567567000167530ustar00rootroot00000000000000require 'ae' AE.ansi = false ruby-xdg-2.2.3/demo/applique/fakeroot.rb000066400000000000000000000007711334567567000202070ustar00rootroot00000000000000require 'fileutils' dir = File.expand_path(File.dirname(File.dirname(__FILE__))) $froot = File.join(dir, 'fixtures/fakeroot/') puts "Fake root at: `#{$froot}'." # ENV['HOME'] = $froot + 'home/joe' #ENV['XDG_DATA_HOME'] = $froot + '.local/share' ENV['XDG_DATA_DIRS'] = $froot + 'usr/share' #ENV['XDG_CONFIG_HOME'] = $froot + '.config' ENV['XDG_CONFIG_DIRS'] = $froot + 'etc/xdg' + ':' + $froot + 'etc' #ENV['XDG_CACHE_HOME'] = $froot + '.cache' ENV['XDG_CACHE_DIRS'] = $froot + 'tmp' ruby-xdg-2.2.3/demo/applique/xdg.rb000066400000000000000000000000161334567567000171470ustar00rootroot00000000000000require 'xdg' ruby-xdg-2.2.3/demo/fixtures/000077500000000000000000000000001334567567000160745ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/000077500000000000000000000000001334567567000177065ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/.cache/000077500000000000000000000000001334567567000210275ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/.cache/DUMMY.txt000066400000000000000000000000771334567567000224670ustar00rootroot00000000000000Just here to provide a file for github to keep this directory. ruby-xdg-2.2.3/demo/fixtures/fakeroot/etc/000077500000000000000000000000001334567567000204615ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/etc/xdg/000077500000000000000000000000001334567567000212435ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/etc/xdg/bar.config000066400000000000000000000000131334567567000231700ustar00rootroot00000000000000BAR.CONFIG ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/000077500000000000000000000000001334567567000206365ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/.cache/000077500000000000000000000000001334567567000217575ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/.cache/foo.cache000066400000000000000000000000121334567567000235200ustar00rootroot00000000000000FOO.CACHE ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/.config/000077500000000000000000000000001334567567000221615ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/.config/foo.config000066400000000000000000000000131334567567000241250ustar00rootroot00000000000000FOO.CONFIG ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/.local/000077500000000000000000000000001334567567000220065ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/.local/share/000077500000000000000000000000001334567567000231105ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/.local/share/foo.dat000066400000000000000000000000101334567567000243540ustar00rootroot00000000000000FOO.DAT ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/joe/000077500000000000000000000000001334567567000214135ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/home/joe/foo.txt000066400000000000000000000000111334567567000227270ustar00rootroot00000000000000FOO TEXT ruby-xdg-2.2.3/demo/fixtures/fakeroot/usr/000077500000000000000000000000001334567567000205175ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/usr/share/000077500000000000000000000000001334567567000216215ustar00rootroot00000000000000ruby-xdg-2.2.3/demo/fixtures/fakeroot/usr/share/bar.dat000066400000000000000000000000101334567567000230460ustar00rootroot00000000000000BAR.DAT ruby-xdg-2.2.3/lib/000077500000000000000000000000001334567567000140455ustar00rootroot00000000000000ruby-xdg-2.2.3/lib/xdg.rb000066400000000000000000000027001334567567000151530ustar00rootroot00000000000000# XDG Base Directory Standard # # This provides a conveient library for conforming to the # XDG Base Directory Standard. # # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html # # Some important clarifications, not made clear by the above specification. # # The data directories are for "read-only" files. In other words once # something is put there, it should only be read, and never written to # by a program. (Generally speaking only users or package managers should # be adding, changing or removing files from the data locations.) # # The config locations are where you store files that may change, # and effect your applications depending on their content. This is like # etc/ in the FHS, but alterable by end users and end user programs, # not just root and sudo admin scripts. # # The cache locations stores files that could just as well be deleted # and everything would still work fine. This is for variable and # temporary files. Much like var/ and tmp/ in FHS. # # The module returns all paths as String. # module XDG if RUBY_VERSION > '1.9' require_relative 'xdg/version' require_relative 'xdg/base_dir' require_relative 'xdg/base_dir/extended' require_relative 'xdg/base_dir/mixin' else require 'xdg/version' require 'xdg/base_dir' require 'xdg/base_dir/extended' require 'xdg/base_dir/mixin' end # def self.[](*env_path) BaseDir.new(*env_path) end end # Copyright (c) 2008 Rubyworks ruby-xdg-2.2.3/lib/xdg/000077500000000000000000000000001334567567000146275ustar00rootroot00000000000000ruby-xdg-2.2.3/lib/xdg/base_dir.rb000066400000000000000000000151211334567567000167240ustar00rootroot00000000000000module XDG # Base Directory Standard class BaseDir # Try to get information from Ruby's install configuration. require 'rbconfig' sysconfdir = ::RbConfig::CONFIG['sysconfdir'] || '/etc' datadir = ::RbConfig::CONFIG['datadir'] || '/usr/share' # Standard defaults for locations. DEFAULTS = { 'XDG_DATA_HOME' => ['~/.local/share'], 'XDG_DATA_DIRS' => ['/usr/local/share', datadir], 'XDG_CONFIG_HOME' => ['~/.config'], 'XDG_CONFIG_DIRS' => [File.join(sysconfdir,'xdg'), sysconfdir], 'XDG_CACHE_HOME' => ['~/.cache'], 'XDG_CACHE_DIRS' => ['/tmp'] } # BaseDir iterates over directory paths. include Enumerable # Shortcut for `BaseDir.new`. def self.[](*env) new(*env) end # Initialize new instance of BaseDir class. def initialize(*env) @environment_variables = [] env.each do |v| v = v.to_s.upcase if v !~ /_/ @environment_variables << 'XDG_' + v + '_HOME' @environment_variables << 'XDG_' + v + '_DIRS' else @environment_variables << 'XDG_' + v end end end # The environment variables being referenced. # # @return [Array] list of XDG environment variable names def environment_variables @environment_variables end # The environment setting, or it's equivalent when the BaseDir # is a combination of environment variables. # # @return [String] evnironment vsetting def environment environment_variables.map{ |v| ENV[v] }.join(':') end # This is same as #environment, but also includes default values. # # @return [String] envinronment value. def environment_with_defaults environment_variables.map{ |v| ENV[v] || DEFAULTS[v] }.join(':') end # Shortcut for #environment_with_defaults. alias_method :env, :environment_with_defaults # Returns a complete list of expanded directories. # # @return [Array] expanded directory list def to_a environment_variables.map do |v| if paths = ENV[v] dirs = paths.split(/[:;]/) else dirs = DEFAULTS[v] end dirs.map{ |path| expand(path) } end.flatten end # BaseDir is essentially an array. alias_method :to_ary, :to_a # Number of directory paths. def size to_a.size end # Iterate of each directory. def each(&block) to_a.each(&block) end # Returns an *unexpanded* list of directories. # # @return [Array] unexpanded directory list def list environment_variables.map do |v| if paths = ENV[v] dirs = paths.split(/[:;]/) else dirs = DEFAULTS[v] end if subdirectory dirs.map{ |path| File.join(path, subdirectory) } else dirs end end.flatten end # List of directories as Pathanme objects. # # @return [Array] list of directories as Pathname objects def paths map{ |dir| Pathname.new(dir) } end # Returns the first directory expanded. Since a environment settings # like `*_HOME` will only have one directory entry, this definition # of #to_s makes utilizing those more convenient. # # @return [String] directory def to_s to_a.first end # The first directory converted to a Pathname object. # # @return [Pathname] pathname of first directory def to_path Pathname.new(to_a.first) end # The common subdirectory. attr :subdirectory # Set subdirectory to be applied to all paths. def subdirectory=(path) @subdirectory = path.to_s end # Set subdirectory to be applied to all paths and return `self`. # # @return [BaseDir] self def with_subdirectory(path) @subdirectory = path if path self end # Return array of matching files or directories # in any of the resource locations, starting with # the home directory and searching outward into # system directories. # # Unlike #select, this doesn't take a block and each # additional glob argument is treated as a logical-or. # # XDG[:DATA].glob("stick/*.rb", "stick/*.yaml") # def glob(*glob_and_flags) glob, flags = *parse_arguments(*glob_and_flags) find = [] to_a.each do |dir| glob.each do |pattern| find.concat(Dir.glob(File.join(dir, pattern), flags)) end end find.uniq end # Return array of matching files or directories # in any of the resource locations, starting with # the home directory and searching outward into # system directories. # # String parameters are joined into a pathname # while Integers and Symbols treated as flags. # # For example, the following are equivalent: # # XDG::BaseDir[:DATA,:HOME].select('stick/units', File::FNM_CASEFOLD) # # XDG::BaseDir[:DATA,:HOME].select('stick', 'units', :casefold) # def select(*glob_and_flags, &block) glob, flag = *parse_arguments(*glob_and_flags) find = [] to_a.each do |dir| path = File.join(dir, *glob) hits = Dir.glob(path, flag) hits = hits.select(&block) if block_given? find.concat(hits) end find.uniq end # Find a file or directory. This works just like #select # except that it returns the first match found. # # TODO: It would be more efficient to traverse the dirs and use #fnmatch. def find(*glob_and_flags, &block) glob, flag = *parse_arguments(*glob_and_flags) find = nil to_a.each do |dir| path = File.join(dir, *glob) hits = Dir.glob(path, flag) hits = hits.select(&block) if block_given? find = hits.first break if find end find end private def parse_arguments(*glob_and_flags) glob, flags = *glob_and_flags.partition{ |e| String===e } glob = ['**/*'] if glob.empty? flag = flags.inject(0) do |m, f| if Symbol === f m + File::const_get("FNM_#{f.to_s.upcase}") else m + f.to_i end end return glob, flag end # def expand(path) if subdirectory File.expand_path(File.join(path, subdirectory)) else File.expand_path(path) end end # If Pathname is referenced the library is automatically loaded. def self.const_missing(const) if const == :Pathname require 'pathname' ::Pathname else super(const) end end end end # Copyright (c) 2008 Rubyworks ruby-xdg-2.2.3/lib/xdg/base_dir/000077500000000000000000000000001334567567000163775ustar00rootroot00000000000000ruby-xdg-2.2.3/lib/xdg/base_dir/extended.rb000066400000000000000000000006731334567567000205320ustar00rootroot00000000000000module XDG # Base directory interface class. class BaseDir # DEFAULTS['XDG_RESOURCE_HOME'] = ['~/.local'] DEFAULTS['XDG_RESOURCE_DIRS'] = ['/usr/local','/usr'] # Working directory # TODO: Not sure about these defaults DEFAULTS['XDG_CONFIG_WORK'] = ['.config','config'] DEFAULTS['XDG_CACHE_WORK'] = ['.tmp','tmp'] DEFAULTS['XDG_RESOURCE_WORK'] = ['.local'] end end # Copyright (c) 2008 Rubyworks ruby-xdg-2.2.3/lib/xdg/base_dir/global_variables.rb000066400000000000000000000011001334567567000222040ustar00rootroot00000000000000if RUBY_VERSION > '1.9' require_relative 'base_dir' else require 'xdg/base_dir' end $XDG_DATA = XDG::BaseDir.new('DATA') $XDG_DATA_HOME = XDG::BaseDir.new('DATA', 'HOME') $XDG_DATA_DIRS = XDG::BaseDir.new('DATA', 'DIRS') $XDG_CONFIG = XDG::BaseDir.new('CONFIG') $XDG_CONFIG_HOME = XDG::BaseDir.new('CONFIG', 'HOME') $XDG_CONFIG_DIRS = XDG::BaseDir.new('CONFIG', 'DIRS') $XDG_CACHE = XDG::BaseDir.new('CACHE') $XDG_CACHE_HOME = XDG::BaseDir.new('CACHE', 'HOME') $XDG_CACHE_DIRS = XDG::BaseDir.new('CACHE', 'DIRS') # Copyright (c) 2008 Rubyworks ruby-xdg-2.2.3/lib/xdg/base_dir/legacy.rb000066400000000000000000000025171334567567000201750ustar00rootroot00000000000000module XDG class BaseDir # Legacy API can serve as a stop gap until a developer # has time to update an program already using XDG. # # Do NOT use this module for future development!!! module Legacy # require 'xdg' require 'xdg/base_dir/extended' # extend self # def home File.expand_path('~') end # def data obj = XDG['DATA'] class << obj def home XDG['DATA_HOME'].to_a.first end def dirs XDG['DATA_DIRS'].to_a end end return obj end # def config obj = XDG['CONFIG'] class << obj def home XDG['CONFIG_HOME'].to_a.first end def dirs XDG['CONFIG_DIRS'].to_a end def work XDG['CONFIG_WORK'].to_a end end return obj end # def cache obj = XDG['CACHE'] class << obj def home XDG['CACHE_HOME'].to_a.first end def dirs XDG['CACHE_DIRS'].to_a end def work XDG['CACHE_WORK'].to_a end end return obj end end end extend BaseDir::Legacy end # Copyright (c) 2008 Rubyworks ruby-xdg-2.2.3/lib/xdg/base_dir/mixin.rb000066400000000000000000000035521334567567000200550ustar00rootroot00000000000000module XDG class BaseDir # # The BaseDir::Mixin module can be used to add XDG base directory # methods to your own classes. # # class MyAppConfig # include XDG::BaseDir::Mixin # # def subdirectory # 'myapp' # end # end # # c = MyAppConfig.new # # c.config.home.list #=> ['~/.config/myapp'] # module Mixin # @todo do we need this? extend self # Override this method to change the subdirectory of the mixin. def subdirectory nil end # def home File.expand_path('~') end # def data obj = XDG['DATA'].with_subdirectory(subdirectory) class << obj def home XDG['DATA_HOME'].with_subdirectory(subdirectory) end def dirs XDG['DATA_DIRS'].with_subdirectory(subdirectory) end end return obj end # def config obj = XDG['CONFIG'].with_subdirectory(subdirectory) class << obj def home XDG['CONFIG_HOME'].with_subdirectory(subdirectory) end def dirs XDG['CONFIG_DIRS'].with_subdirectory(subdirectory) end def work XDG['CONFIG_WORK'].with_subdirectory(subdirectory) end end return obj end # def cache obj = XDG['CACHE'].with_subdirectory(subdirectory) class << obj def home XDG['CACHE_HOME'].with_subdirectory(subdirectory) end def dirs XDG['CACHE_DIRS'].with_subdirectory(subdirectory) end def work XDG['CACHE_WORK'].with_subdirectory(subdirectory) end end return obj end end end end # Copyright (c) 2008 Rubyworks ruby-xdg-2.2.3/lib/xdg/version.rb000066400000000000000000000000431334567567000166360ustar00rootroot00000000000000module XDG VERSION = '2.2.3' end ruby-xdg-2.2.3/test/000077500000000000000000000000001334567567000142565ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/000077500000000000000000000000001334567567000160705ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/.cache/000077500000000000000000000000001334567567000172115ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/.cache/DUMMY.txt000066400000000000000000000000771334567567000206510ustar00rootroot00000000000000Just here to provide a file for github to keep this directory. ruby-xdg-2.2.3/test/fakeroot/etc/000077500000000000000000000000001334567567000166435ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/etc/xdg/000077500000000000000000000000001334567567000174255ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/etc/xdg/bar.config000066400000000000000000000000131334567567000213520ustar00rootroot00000000000000BAR.CONFIG ruby-xdg-2.2.3/test/fakeroot/home/000077500000000000000000000000001334567567000170205ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/home/.cache/000077500000000000000000000000001334567567000201415ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/home/.cache/foo.cache000066400000000000000000000000121334567567000217020ustar00rootroot00000000000000FOO.CACHE ruby-xdg-2.2.3/test/fakeroot/home/.config/000077500000000000000000000000001334567567000203435ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/home/.config/foo.config000066400000000000000000000000131334567567000223070ustar00rootroot00000000000000FOO.CONFIG ruby-xdg-2.2.3/test/fakeroot/home/.local/000077500000000000000000000000001334567567000201705ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/home/.local/share/000077500000000000000000000000001334567567000212725ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/home/.local/share/foo.dat000066400000000000000000000000101334567567000225360ustar00rootroot00000000000000FOO.DAT ruby-xdg-2.2.3/test/fakeroot/usr/000077500000000000000000000000001334567567000167015ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/usr/share/000077500000000000000000000000001334567567000200035ustar00rootroot00000000000000ruby-xdg-2.2.3/test/fakeroot/usr/share/bar.dat000066400000000000000000000000101334567567000212300ustar00rootroot00000000000000BAR.DAT ruby-xdg-2.2.3/test/test_xdg_legacy.rb000066400000000000000000000061751334567567000177610ustar00rootroot00000000000000$:.unshift 'lib' require 'xdg/base_dir/legacy' require 'test/unit' # run test from fakeroot directory. Dir.chdir(File.join(File.dirname(__FILE__), 'fakeroot')) ENV['HOME'] = File.join(Dir.pwd, 'home') ENV['XDG_DATA_DIRS'] = File.join(Dir.pwd, 'usr/share') ENV['XDG_CONFIG_DIRS'] = File.join(Dir.pwd, 'etc/xdg') class TestXDG < Test::Unit::TestCase # Test the standard paths. def test_home assert_equal(File.join(Dir.pwd,'home'), XDG.home) end def test_config_home assert_equal(File.join(Dir.pwd,'home/.config'), XDG.config.home) end def test_config_dirs assert_equal([File.join(Dir.pwd,"etc/xdg")], XDG.config.dirs) end def test_data_home assert_equal(File.join(Dir.pwd,'home/.local/share'), XDG.data.home) end def test_data_dirs assert_equal([File.join(Dir.pwd,'usr/share')], XDG.data.dirs) end def test_cache_home assert_equal(File.join(Dir.pwd,'home/.cache'), XDG.cache.home) end # Test the find methods. def test_data_find file = 'foo.dat' assert_equal(File.join(Dir.pwd,'home/.local/share', file), XDG.data.find(file)) file = 'bar.dat' assert_equal(File.join(Dir.pwd,'usr/share', file), XDG.data.find(file)) end def test_config_find file = 'foo.config' assert_equal(File.join(Dir.pwd,'home/.config', file), XDG.config.find(file)) file = 'bar.config' assert_equal(File.join(Dir.pwd,'etc/xdg', file), XDG.config.find(file)) end def test_cache_find file = 'foo.cache' assert_equal(File.join(Dir.pwd,'home/.cache', file), XDG.cache.find(file)) end # Test the glob methods. def test_data_select file = 'foo.dat' assert_equal([File.join(Dir.pwd,'home/.local/share', file)], XDG.data.select(file)) file = 'bar.dat' assert_equal([File.join(Dir.pwd,'usr/share', file)], XDG.data.select(file)) end def test_config_select file = 'foo.config' assert_equal([File.join(Dir.pwd,'home/.config', file)], XDG.config.select(file)) file = 'bar.config' assert_equal([File.join(Dir.pwd,'etc/xdg', file)], XDG.config.select(file)) end def test_cache_select file = 'foo.cache' assert_equal([File.join(Dir.pwd,'home/.cache', file)], XDG.cache.select(file)) end # Test the glob methods. def test_data_glob file = 'foo.dat' assert_equal([File.join(Dir.pwd,'home/.local/share', file)], XDG.data.glob(file)) file = 'bar.dat' assert_equal([File.join(Dir.pwd,'usr/share', file)], XDG.data.glob(file)) end def test_config_glob file = 'foo.config' assert_equal([File.join(Dir.pwd,'home/.config', file)], XDG.config.glob(file)) file = 'bar.config' assert_equal([File.join(Dir.pwd,'etc/xdg', file)], XDG.config.glob(file)) end def test_cache_glob file = 'foo.cache' assert_equal([File.join(Dir.pwd,'home/.cache', file)], XDG.cache.glob(file)) end # Test the working directory variations. def test_config_work result = [File.join(Dir.pwd,'.config'), File.join(Dir.pwd,'config')] assert_equal(result, XDG.config.work) end def test_cache_work result = [File.join(Dir.pwd,'.tmp'), File.join(Dir.pwd,'tmp')] assert_equal(result, XDG.cache.work) end end ruby-xdg-2.2.3/xdg.gemspec000066400000000000000000000057021334567567000154320ustar00rootroot00000000000000######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: xdg 2.2.3 ruby lib Gem::Specification.new do |s| s.name = "xdg".freeze s.version = "2.2.3" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Trans".freeze] s.date = "2012-12-12" s.description = "XDG provides a module for supporting the XDG Base Directory Standard. See http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html".freeze s.email = ["transfire@gmail.com".freeze] s.extra_rdoc_files = ["DEMO.md".freeze, "HISTORY.md".freeze, "LICENSE.txt".freeze, "README.md".freeze] s.files = [".index".freeze, ".yardopts".freeze, "DEMO.md".freeze, "HISTORY.md".freeze, "LICENSE.txt".freeze, "README.md".freeze, "demo/01_base_dir.md".freeze, "demo/02_base_dir_extended.md".freeze, "demo/03_base_dir_mixin.md".freeze, "demo/applique/ae.rb".freeze, "demo/applique/fakeroot.rb".freeze, "demo/applique/xdg.rb".freeze, "demo/fixtures/fakeroot/.cache/DUMMY.txt".freeze, "demo/fixtures/fakeroot/etc/xdg/bar.config".freeze, "demo/fixtures/fakeroot/home/.cache/foo.cache".freeze, "demo/fixtures/fakeroot/home/.config/foo.config".freeze, "demo/fixtures/fakeroot/home/.local/share/foo.dat".freeze, "demo/fixtures/fakeroot/home/joe/foo.txt".freeze, "demo/fixtures/fakeroot/usr/share/bar.dat".freeze, "lib/xdg.rb".freeze, "lib/xdg/base_dir.rb".freeze, "lib/xdg/base_dir/extended.rb".freeze, "lib/xdg/base_dir/global_variables.rb".freeze, "lib/xdg/base_dir/legacy.rb".freeze, "lib/xdg/base_dir/mixin.rb".freeze, "lib/xdg/version.rb".freeze, "test/fakeroot/.cache/DUMMY.txt".freeze, "test/fakeroot/etc/xdg/bar.config".freeze, "test/fakeroot/home/.cache/foo.cache".freeze, "test/fakeroot/home/.config/foo.config".freeze, "test/fakeroot/home/.local/share/foo.dat".freeze, "test/fakeroot/usr/share/bar.dat".freeze, "test/test_xdg_legacy.rb".freeze] s.homepage = "http://rubyworks.github.com/xdg".freeze s.licenses = ["BSD-2-Clause".freeze] s.rubygems_version = "2.7.6".freeze s.summary = "XDG provides an interface for using XDG directory standard.".freeze s.test_files = ["test/test_xdg_legacy.rb".freeze] if s.respond_to? :specification_version then s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) end else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) end end