Module: Config
- Defined in:
- lib/roll/config.rb
Constant Summary collapse
- HOME =
File.('~')
- CONFIG_HOME =
Location of user’s personal config directory.
File.(ENV['XDG_CONFIG_HOME'] || File.join(HOME, '.config'))
- CONFIG_DIRS =
List of user shared system config directories.
( dirs = ENV['XDG_CONFIG_DIRS'].to_s.split(/[:;]/) if dirs.empty? dirs = File.join(Config::CONFIG['sysconfdir'], 'xdg') end dirs.collect{ |d| File.(d) } )
- WIN_PATTERNS =
[ /bccwin/i, /cygwin/i, /djgpp/i, /mingw/i, /mswin/i, /wince/i, ]
Class Method Summary collapse
-
.confdir(name) ⇒ Object
Return the path to the configuration directory.
-
.datadir(name, versionless = false) ⇒ Object
Return the path to the data directory associated with the given library name.
-
.find_config(*glob) ⇒ Object
Lookup configuration file.
-
.win_platform? ⇒ Boolean
Is this a windows platform?.
Class Method Details
.confdir(name) ⇒ Object
Return the path to the configuration directory.
54 55 56 57 58 59 60 |
# File 'lib/roll/config.rb', line 54 def self.confdir(name) if lib = Roll::Library.instance(name) lib.confdir else File.join(CONFIG['confdir'], name) end end |
.datadir(name, versionless = false) ⇒ Object
Return the path to the data directory associated with the given library name. – Normally this is just “#'datadir'/#name”, but may be modified by packages like RubyGems and Rolls to handle versioned data directories. ++
44 45 46 47 48 49 50 |
# File 'lib/roll/config.rb', line 44 def self.datadir(name, versionless=false) if lib = Roll::Library.instance(name) lib.datadir(versionless) else File.join(CONFIG['datadir'], name) end end |
.find_config(*glob) ⇒ Object
Lookup configuration file.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/roll/config.rb', line 64 def self.find_config(*glob) flag = 0 flag = (flag | glob.pop) while Fixnum === glob.last find = [] [CONFIG_HOME, *CONFIG_DIRS].each do |dir| path = File.join(dir, *glob) if block_given? find.concat(Dir.glob(path, flag).select(&block)) else find.concat(Dir.glob(path, flag)) end end find end |
.win_platform? ⇒ Boolean
Is this a windows platform?
29 30 31 32 33 |
# File 'lib/roll/config.rb', line 29 def self.win_platform? @win_platform ||= ( !!WIN_PATTERNS.find{ |r| RUBY_PLATFORM =~ r } ) end |