xdg 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. data/HISTORY +8 -1
  2. data/MANIFEST +1 -0
  3. data/RELEASE +18 -7
  4. data/VERSION +1 -1
  5. data/lib/xdg.rb +99 -51
  6. data/test/test_xdg.rb +48 -27
  7. metadata +17 -25
data/HISTORY CHANGED
@@ -1,4 +1,11 @@
1
- ### 0.3.0 / 2008-09-11
1
+ = CHANGE HISTORY
2
+
3
+ === 0.4.0 / 2008-10-26
4
+
5
+ * Renamed instance level methods without 'xdg_' prefix.
6
+ * Replace _file methods with _find and _glob methods.
7
+
8
+ === 0.3.0 / 2008-09-11
2
9
 
3
10
  * Renamed module level methods without 'xdg_' prefix.
4
11
  * The xdg_ versions still exist for backward compatibility.
data/MANIFEST CHANGED
@@ -1,3 +1,4 @@
1
+ MANIFEST
1
2
  test
2
3
  test/fakeroot
3
4
  test/fakeroot/home
data/RELEASE CHANGED
@@ -1,10 +1,21 @@
1
- This release removes the xdg_ prefix from the module-level
2
- method names. The instance methods retain the xdg_ prefix.
3
- I will consider if they should also be removed for the
4
- next release.
1
+ = XDG 0.4 hits the streets!
5
2
 
6
- ### 0.3.0 / 2008-09-11
3
+ http://xdg.rubyforge.org
7
4
 
8
- * Renamed module level methods without 'xdg_' prefix.
9
- * The xdg_ versions still exist for backward compatibility.
5
+ This release removes the xdg_ prefix from the instance-level
6
+ method names. Now module and instance levels are the same.
7
+
8
+ Also, data_file, config_file and cache_file have been replaced with
9
+ data_find, config_find, cache_find, data_glob, config_glob and
10
+ cache_glob.
11
+
12
+ What' next? Well, I can't say I'm fond of the term 'glob', so I
13
+ may rename that to 'map' or 'collect' (or 'select'?) and then
14
+ add the ability to use blocks for matching too.
15
+
16
+
17
+ ### 0.4.0 / 2008-10-26
18
+
19
+ * Renamed instance level methods without 'xdg_' prefix.
20
+ * Replace _file methods with _find and _glob methods.
10
21
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- xdg 0.3.0 beta (2008-09-30)
1
+ xdg 0.4.0 beta (2008-10-26)
data/lib/xdg.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  # :Copyright: (c)2008 Tiger Ops
4
4
  # :License: GPLv3
5
5
 
6
-
7
6
  # = XDG Base Directory Standard
8
7
  #
9
8
  # This provides a conveient library for conforming to the
@@ -32,19 +31,21 @@
32
31
 
33
32
  module XDG
34
33
 
35
- def self.home
34
+ extend self #module_function
35
+
36
+ def home
36
37
  ENV['HOME'] || File.expand_path('~')
37
38
  end
38
39
 
39
40
  # Location of user's personal config directory.
40
- def self.config_home
41
+ def config_home
41
42
  File.expand_path(
42
- ENV['XDG_CONFIG_HOME'] || File.join(xdg_home, '.config')
43
+ ENV['XDG_CONFIG_HOME'] || File.join(home, '.config')
43
44
  )
44
45
  end
45
46
 
46
47
  # List of user's shared config directories.
47
- def self.config_dirs
48
+ def config_dirs
48
49
  dirs = ENV['XDG_CONFIG_DIRS'].to_s.split(/[:;]/)
49
50
  if dirs.empty?
50
51
  dirs = %w{/etc/xdg}
@@ -53,14 +54,14 @@ module XDG
53
54
  end
54
55
 
55
56
  # Location of user's personal data directory.
56
- def self.data_home
57
+ def data_home
57
58
  File.expand_path(
58
- ENV['XDG_DATA_HOME'] || File.join(xdg_home, '.local', 'share')
59
+ ENV['XDG_DATA_HOME'] || File.join(home, '.local', 'share')
59
60
  )
60
61
  end
61
62
 
62
63
  # List of user's shared data directores.
63
- def self.data_dirs
64
+ def data_dirs
64
65
  dirs = ENV['XDG_DATA_DIRS'].split(/[:;]/)
65
66
  if dirs.empty?
66
67
  dirs = %w{/usr/local/share/ /usr/share/}
@@ -69,85 +70,132 @@ module XDG
69
70
  end
70
71
 
71
72
  # Location of user's personal cache directory.
72
- def self.cache_home
73
+ def cache_home
73
74
  File.expand_path(
74
- ENV['XDG_CACHE_HOME'] || File.join(xdg_home, '.cache')
75
+ ENV['XDG_CACHE_HOME'] || File.join(home, '.cache')
75
76
  )
76
77
  end
77
78
 
78
79
  # Find a file or directory in data dirs.
79
- def self.data_file(file)
80
- find = nil
81
- [xdg_data_home, *xdg_data_dirs].each do |dir|
82
- path = File.join(dir,file)
83
- break find = path if File.exist?(path)
80
+ def data_find(*glob_and_flags)
81
+ data_glob(*glob_and_flags).first
82
+ end
83
+
84
+ def data_glob(*glob_and_flags)
85
+ glob, flags = *glob_and_flags.partition{ |e| String===e }
86
+ flag = flags.inject(0) do |m, f|
87
+ if Symbol === f
88
+ m + File::const_get("FNM_#{f.to_s.upcase}")
89
+ else
90
+ m + f.to_i
91
+ end
92
+ end
93
+ find = []
94
+ [data_home, *data_dirs].each do |dir|
95
+ path = File.join(dir, *glob)
96
+ find.concat(Dir.glob(path, flag))
84
97
  end
85
98
  find
86
99
  end
87
100
 
88
- # Find a file or directory in config dirs.
89
- def self.config_file(file)
90
- find = nil
91
- [xdg_config_home, *xdg_config_dirs].each do |dir|
92
- path = File.join(dir,file)
93
- break find = path if File.exist?(path)
101
+ # Return the fist matching file or directory
102
+ # from the config locations.
103
+ #
104
+ # See +config_glog+.
105
+ def config_find(*glob_and_flags)
106
+ config_glob(*glob_and_flags).first
107
+ end
108
+
109
+ # Return array of matching files or directories
110
+ # in any of the config locations.
111
+ #
112
+ # This starts with the user's home directory
113
+ # and then searches system directories.
114
+ #
115
+ # String parameters are joined into a pathname
116
+ # while Integers and Symbols treated as flags.
117
+ #
118
+ # For example, the following are equivalent:
119
+ #
120
+ # XDG.config_glob('sow/plugins', File::FNM_CASEFOLD)
121
+ #
122
+ # XDG.config_glob('sow', 'plugins', :casefold)
123
+ #
124
+ def config_glob(*glob_and_flags)
125
+ glob, flags = *glob_and_flags.partition{ |e| String===e }
126
+ flag = flags.inject(0) do |m, f|
127
+ if Symbol === f
128
+ m + File::const_get("FNM_#{f.to_s.upcase}")
129
+ else
130
+ m + f.to_i
131
+ end
132
+ end
133
+ find = []
134
+ [config_home, *config_dirs].each do |dir|
135
+ path = File.join(dir, *glob)
136
+ find.concat(Dir.glob(path, flag))
94
137
  end
95
138
  find
96
139
  end
97
140
 
98
- # Find a file or directory in the user cache.
99
- def self.cache_file(file)
100
- path = File.join(xdg_cache_home,file)
101
- File.exist?(path) ? path : nil
141
+ # Return the fist matching file or directory
142
+ # in the cache directory.
143
+ #
144
+ # See +cache_glog+.
145
+ def cache_find(*glob_and_flags)
146
+ cache_glob(*glob_and_flags).first
147
+ end
148
+
149
+ # Return array of matching files or directories
150
+ # from the cache directory.
151
+ #
152
+ # String parameters are joined into a pathname
153
+ # while Integers and Symbols treated as flags.
154
+ #
155
+ # For example, the following are equivalent:
156
+ #
157
+ # XDG.cache_glob('sow/tmp', File::FNM_CASEFOLD)
158
+ #
159
+ # XDG.cache_glob('sow', 'tmp', :casefold)
160
+ #
161
+ def cache_glob(*glob_and_flags)
162
+ glob, flags = *glob_and_flags.partition{ |e| String===e }
163
+ flag = flags.inject(0) do |m, f|
164
+ if Symbol === f
165
+ m + File::const_get("FNM_#{f.to_s.upcase}")
166
+ else
167
+ m + f.to_i
168
+ end
169
+ end
170
+ path = File.join(cache_home,*glob)
171
+ Dir.glob(path, flag)
102
172
  end
103
173
 
104
174
  #--
105
175
  # The following are not strictly XDG spec,
106
- # but are useful in the same respect.
176
+ # but are useful in a similar respect.
107
177
  #++
108
178
 
109
179
  # Location of working config directory.
110
- def self.config_work
180
+ def config_work
111
181
  File.expand_path(
112
- #ENV['XDG_CONFIG_WORK'] || File.join(Dir.pwd, '.config')
113
182
  File.join(Dir.pwd, '.config')
114
183
  )
115
184
  end
116
185
 
117
186
  # Location of working data directory.
118
- def self.data_work
187
+ def data_work
119
188
  File.expand_path(
120
- #ENV['XDG_DATA_WORK'] || File.join(Dir.pwd, '.share')
121
189
  File.join(Dir.pwd, '.share')
122
190
  )
123
191
  end
124
192
 
125
193
  # Location of working cache directory.
126
- def self.cache_work
194
+ def cache_work
127
195
  File.expand_path(
128
- #ENV['XDG_CACHE_WORK'] || File.join(Dir.pwd, '.cache')
129
196
  File.join(Dir.pwd, '.cache')
130
197
  )
131
198
  end
132
199
 
133
- ###############
134
- module_function
135
- ###############
136
-
137
- def xdg_home ; XDG.home ; end
138
- def xdg_config_home ; XDG.config_home ; end
139
- def xdg_config_dirs ; XDG.config_dirs ; end
140
- def xdg_data_home ; XDG.data_home ; end
141
- def xdg_data_dirs ; XDG.data_dirs ; end
142
- def xdg_cache_home ; XDG.cache_home ; end
143
-
144
- def xdg_data_file(file) ; XDG.data_file(file) ; end
145
- def xdg_config_file(file) ; XDG.config_file(file) ; end
146
- def xdg_cache_file(file) ; XDG.cache_file(file) ; end
147
-
148
- def xdg_config_work ; XDG.config_work ; end
149
- def xdg_data_work ; XDG.data_work ; end
150
- def xdg_cache_work ; XDG.cache_work ; end
151
-
152
200
  end # module XDG
153
201
 
@@ -13,63 +13,84 @@ class TestXDG < Test::Unit::TestCase
13
13
 
14
14
  # Test the standard paths.
15
15
 
16
- def test_xdg_home
17
- assert_equal(File.join(Dir.pwd,'home'), XDG.xdg_home)
16
+ def test_home
17
+ assert_equal(File.join(Dir.pwd,'home'), XDG.home)
18
18
  end
19
19
 
20
- def test_xdg_config_home
21
- assert_equal(File.join(Dir.pwd,'home/.config'), XDG.xdg_config_home)
20
+ def test_config_home
21
+ assert_equal(File.join(Dir.pwd,'home/.config'), XDG.config_home)
22
22
  end
23
23
 
24
- def test_xdg_config_dirs
25
- assert_equal([File.join(Dir.pwd,"etc/xdg")], XDG.xdg_config_dirs)
24
+ def test_config_dirs
25
+ assert_equal([File.join(Dir.pwd,"etc/xdg")], XDG.config_dirs)
26
26
  end
27
27
 
28
- def test_xdg_data_home
29
- assert_equal(File.join(Dir.pwd,'home/.local/share'), XDG.xdg_data_home)
28
+ def test_data_home
29
+ assert_equal(File.join(Dir.pwd,'home/.local/share'), XDG.data_home)
30
30
  end
31
31
 
32
- def test_xdg_data_dirs
33
- assert_equal([File.join(Dir.pwd,'usr/share')], XDG.xdg_data_dirs)
32
+ def test_data_dirs
33
+ assert_equal([File.join(Dir.pwd,'usr/share')], XDG.data_dirs)
34
34
  end
35
35
 
36
- def test_xdg_cache_home
37
- assert_equal(File.join(Dir.pwd,'home/.cache'), XDG.xdg_cache_home)
36
+ def test_cache_home
37
+ assert_equal(File.join(Dir.pwd,'home/.cache'), XDG.cache_home)
38
38
  end
39
39
 
40
- # Test the file lookups.
40
+ # Test the find methods.
41
41
 
42
- def test_xdg_data_file
42
+ def test_data_find
43
43
  file = 'foo.dat'
44
- assert_equal(File.join(Dir.pwd,'home/.local/share', file), XDG.xdg_data_file(file))
44
+ assert_equal(File.join(Dir.pwd,'home/.local/share', file), XDG.data_find(file))
45
45
  file = 'bar.dat'
46
- assert_equal(File.join(Dir.pwd,'usr/share', file), XDG.xdg_data_file(file))
46
+ assert_equal(File.join(Dir.pwd,'usr/share', file), XDG.data_find(file))
47
47
  end
48
48
 
49
- def test_xdg_config_file
49
+ def test_config_find
50
50
  file = 'foo.config'
51
- assert_equal(File.join(Dir.pwd,'home/.config', file), XDG.xdg_config_file(file))
51
+ assert_equal(File.join(Dir.pwd,'home/.config', file), XDG.config_find(file))
52
52
  file = 'bar.config'
53
- assert_equal(File.join(Dir.pwd,'etc/xdg', file), XDG.xdg_config_file(file))
53
+ assert_equal(File.join(Dir.pwd,'etc/xdg', file), XDG.config_find(file))
54
54
  end
55
55
 
56
- def test_xdg_cache_file
56
+ def test_cache_find
57
57
  file = 'foo.cache'
58
- assert_equal(File.join(Dir.pwd,'home/.cache', file), XDG.xdg_cache_file(file))
58
+ assert_equal(File.join(Dir.pwd,'home/.cache', file), XDG.cache_find(file))
59
+ end
60
+
61
+ # Test the glob methods.
62
+
63
+ def test_data_glob
64
+ file = 'foo.dat'
65
+ assert_equal(File.join(Dir.pwd,'home/.local/share', file), XDG.data_find(file))
66
+ file = 'bar.dat'
67
+ assert_equal([File.join(Dir.pwd,'usr/share', file)], XDG.data_glob(file))
68
+ end
69
+
70
+ def test_config_glob
71
+ file = 'foo.config'
72
+ assert_equal([File.join(Dir.pwd,'home/.config', file)], XDG.config_glob(file))
73
+ file = 'bar.config'
74
+ assert_equal([File.join(Dir.pwd,'etc/xdg', file)], XDG.config_glob(file))
75
+ end
76
+
77
+ def test_cache_glob
78
+ file = 'foo.cache'
79
+ assert_equal([File.join(Dir.pwd,'home/.cache', file)], XDG.cache_glob(file))
59
80
  end
60
81
 
61
82
  # Test the working directory variations.
62
83
 
63
- def test_xdg_config_work
64
- assert_equal(File.join(Dir.pwd,'.config'), XDG.xdg_config_work)
84
+ def test_config_work
85
+ assert_equal(File.join(Dir.pwd,'.config'), XDG.config_work)
65
86
  end
66
87
 
67
- def test_xdg_data_work
68
- assert_equal(File.join(Dir.pwd,'.share'), XDG.xdg_data_work)
88
+ def test_data_work
89
+ assert_equal(File.join(Dir.pwd,'.share'), XDG.data_work)
69
90
  end
70
91
 
71
- def test_xdg_cache_work
72
- assert_equal(File.join(Dir.pwd,'.cache'), XDG.xdg_cache_work)
92
+ def test_cache_work
93
+ assert_equal(File.join(Dir.pwd,'.cache'), XDG.cache_work)
73
94
  end
74
95
 
75
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xdg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tigerops-community@rubyforge.org
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-10-11 00:00:00 -04:00
13
+ date: 2008-10-26 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -28,21 +28,16 @@ extra_rdoc_files:
28
28
  - VERSION
29
29
  - COPYING
30
30
  files:
31
- - MANIFEST
31
+ - lib
32
+ - meta
32
33
  - test
33
- - test/fakeroot
34
- - test/fakeroot/home
35
- - test/fakeroot/usr
36
- - test/fakeroot/usr/share
37
- - test/fakeroot/usr/share/bar.dat
38
- - test/fakeroot/etc
39
- - test/fakeroot/etc/xdg
40
- - test/fakeroot/etc/xdg/bar.config
41
- - test/test_xdg.rb
34
+ - MANIFEST
42
35
  - RELEASE
43
36
  - README
44
37
  - HISTORY
45
- - meta
38
+ - VERSION
39
+ - COPYING
40
+ - lib/xdg.rb
46
41
  - meta/homepage
47
42
  - meta/summary
48
43
  - meta/abstract
@@ -50,10 +45,15 @@ files:
50
45
  - meta/title
51
46
  - meta/authors
52
47
  - meta/contact
53
- - lib
54
- - lib/xdg.rb
55
- - VERSION
56
- - COPYING
48
+ - test/fakeroot
49
+ - test/test_xdg.rb
50
+ - test/fakeroot/home
51
+ - test/fakeroot/usr
52
+ - test/fakeroot/etc
53
+ - test/fakeroot/usr/share
54
+ - test/fakeroot/usr/share/bar.dat
55
+ - test/fakeroot/etc/xdg
56
+ - test/fakeroot/etc/xdg/bar.config
57
57
  has_rdoc: true
58
58
  homepage: http://xdg.rubyforge.org
59
59
  post_install_message:
@@ -85,12 +85,4 @@ signing_key:
85
85
  specification_version: 2
86
86
  summary: XDG provides a module for supporting the XDG Base Directory Standard.
87
87
  test_files:
88
- - test/fakeroot
89
- - test/fakeroot/home
90
- - test/fakeroot/usr
91
- - test/fakeroot/usr/share
92
- - test/fakeroot/usr/share/bar.dat
93
- - test/fakeroot/etc
94
- - test/fakeroot/etc/xdg
95
- - test/fakeroot/etc/xdg/bar.config
96
88
  - test/test_xdg.rb