Module: Folio::XDG
- Defined in:
- lib/folio/xdg.rb
Overview
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, never written to by a program. (Generally speaking only users or pacakge mangers should be adding, changing or removing files from the data locations.
The config locations are where you should store files that may change, and effect operations depending one there content. This is like etc/ in the FHS, but alterable by end users and and end user programs, not just root and sudo admin scripts.
The cache location stores files that could judt as well be deleted and everyihtng still works find. This is for variable and temporary files. Like var/ in FHS.
This module returns paths as strings.
Class Method Summary collapse
- .home ⇒ Object
-
.xdg_cache_file(file) ⇒ Object
Find a file or directory in the user cache.
-
.xdg_cache_home ⇒ Object
Location of user’s personal cache directory.
-
.xdg_cache_work ⇒ Object
Location of working cache directory.
-
.xdg_config_dirs ⇒ Object
List of user’s shared config directories.
-
.xdg_config_file(file) ⇒ Object
Find a file or directory in config dirs.
-
.xdg_config_home ⇒ Object
Location of user’s personal config directory.
-
.xdg_config_work ⇒ Object
Location of working config directory.
-
.xdg_data_dirs ⇒ Object
List of user’s shared data directores.
-
.xdg_data_file(file) ⇒ Object
Find a file or directory in data dirs.
-
.xdg_data_home ⇒ Object
Location of user’s personal data directory.
-
.xdg_data_work ⇒ Object
Location of working data directory.
Class Method Details
.home ⇒ Object
40 41 42 |
# File 'lib/folio/xdg.rb', line 40 def home ENV['HOME'] || File.('~') end |
.xdg_cache_file(file) ⇒ Object
Find a file or directory in the user cache.
100 101 102 |
# File 'lib/folio/xdg.rb', line 100 def xdg_cache_file(file) File.join(cache_home,file) end |
.xdg_cache_home ⇒ Object
Location of user’s personal cache directory.
77 78 79 80 81 |
# File 'lib/folio/xdg.rb', line 77 def xdg_cache_home File.( ENV['XDG_CACHE_HOME'] || File.join(home, '.cache') ) end |
.xdg_cache_work ⇒ Object
Location of working cache directory.
126 127 128 129 130 131 |
# File 'lib/folio/xdg.rb', line 126 def xdg_cache_work File.( #ENV['XDG_CACHE_WORK'] || File.join(Dir.pwd, '.cache') File.join(Dir.pwd, '.cache') ) end |
.xdg_config_dirs ⇒ Object
List of user’s shared config directories.
52 53 54 55 56 57 58 |
# File 'lib/folio/xdg.rb', line 52 def xdg_config_dirs dirs = ENV['XDG_CONFIG_DIRS'].split(/[:;]/) if dirs.empty? dirs = %w{/etc/xdg} end dir.collect{ |d| File.(d) } end |
.xdg_config_file(file) ⇒ Object
Find a file or directory in config dirs.
92 93 94 95 96 97 |
# File 'lib/folio/xdg.rb', line 92 def xdg_config_file(file) [config_home, *config_dirs].each do |dir| path = File.join(dir,file) break path if File.exist?(path) end end |
.xdg_config_home ⇒ Object
Location of user’s personal config directory.
45 46 47 48 49 |
# File 'lib/folio/xdg.rb', line 45 def xdg_config_home File.( ENV['XDG_CONFIG_HOME'] || File.join(home, '.config') ) end |
.xdg_config_work ⇒ Object
Location of working config directory.
110 111 112 113 114 115 |
# File 'lib/folio/xdg.rb', line 110 def xdg_config_work File.( #ENV['XDG_CONFIG_WORK'] || File.join(Dir.pwd, '.config') File.join(Dir.pwd, '.config') ) end |
.xdg_data_dirs ⇒ Object
List of user’s shared data directores.
68 69 70 71 72 73 74 |
# File 'lib/folio/xdg.rb', line 68 def xdg_data_dirs dirs = ENV['XDG_DATA_DIRS'].split(/[:;]/) if dirs.empty? dirs = %w{/usr/local/share/ /usr/share/} end dir.collect{ |d| File.(d) } end |
.xdg_data_file(file) ⇒ Object
Find a file or directory in data dirs.
84 85 86 87 88 89 |
# File 'lib/folio/xdg.rb', line 84 def xdg_data_file(file) [data_home, *data_dirs].each do |dir| path = File.join(dir,file) break path if File.exist?(path) end end |
.xdg_data_home ⇒ Object
Location of user’s personal data directory.
61 62 63 64 65 |
# File 'lib/folio/xdg.rb', line 61 def xdg_data_home File.( ENV['XDG_DATA_HOME'] || File.join(home, '.local', 'share') ) end |
.xdg_data_work ⇒ Object
Location of working data directory.
118 119 120 121 122 123 |
# File 'lib/folio/xdg.rb', line 118 def xdg_data_work File.( #ENV['XDG_DATA_WORK'] || File.join(Dir.pwd, '.share') File.join(Dir.pwd, '.share') ) end |