xdg 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +33 -0
- data/APACHE2.txt +204 -0
- data/{HISTORY → HISTORY.rdoc} +14 -0
- data/README.rdoc +149 -0
- data/lib/xdg.rb +16 -228
- data/lib/xdg/base_dir.rb +220 -0
- data/lib/xdg/base_dir/extended.rb +20 -0
- data/lib/xdg/base_dir/global_variables.rb +18 -0
- data/lib/xdg/base_dir/legacy.rb +72 -0
- data/lib/xdg/base_dir/mixin.rb +84 -0
- data/lib/xdg/version.rb +3 -0
- data/qed/01_base_dir.rdoc +77 -0
- data/qed/02_base_dir_extended.rb +39 -0
- data/qed/03_base_dir_mixin.rb +19 -0
- data/qed/applique/fakeroot.rb +15 -0
- data/qed/fixtures/fakeroot/etc/xdg/bar.config +1 -0
- data/qed/fixtures/fakeroot/home/.cache/foo.cache +1 -0
- data/qed/fixtures/fakeroot/home/.config/foo.config +1 -0
- data/qed/fixtures/fakeroot/home/.local/share/foo.dat +1 -0
- data/qed/fixtures/fakeroot/home/joe/foo.txt +1 -0
- data/qed/fixtures/fakeroot/usr/share/bar.dat +1 -0
- data/test/{test_xdg.rb → test_xdg_legacy.rb} +6 -4
- metadata +49 -41
- data/COPYING +0 -789
- data/MANIFEST +0 -24
- data/README +0 -97
- data/lib/xdg/compat.rb +0 -66
- data/lib/xdg/extended.rb +0 -84
- data/meta/authors +0 -1
- data/meta/collection +0 -1
- data/meta/contact +0 -1
- data/meta/description +0 -2
- data/meta/homepage +0 -1
- data/meta/name +0 -1
- data/meta/repository +0 -1
- data/meta/summary +0 -1
- data/meta/title +0 -1
- data/meta/version +0 -1
- data/script/test +0 -4
data/.ruby
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
name: xdg
|
3
|
+
version: 2.0.0
|
4
|
+
title: XDG
|
5
|
+
summary: XDG provides an interface for using XDG directory standard.
|
6
|
+
description: XDG provides a module for supporting the XDG Base Directory Standard. See http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
|
7
|
+
loadpath:
|
8
|
+
- lib
|
9
|
+
manifest: Manifest.txt
|
10
|
+
requires: []
|
11
|
+
|
12
|
+
conflicts: []
|
13
|
+
|
14
|
+
replaces: []
|
15
|
+
|
16
|
+
engine_check: []
|
17
|
+
|
18
|
+
organization: RubyWorks
|
19
|
+
contact: Thomas Sawyer <transfire@gmail.com>
|
20
|
+
created: 2008-09-27
|
21
|
+
copyright: Copyright (c) 2008 Thomas Sawyer
|
22
|
+
licenses:
|
23
|
+
- Apache 2.0
|
24
|
+
authors:
|
25
|
+
- Thomas Sawyer
|
26
|
+
maintainers: []
|
27
|
+
|
28
|
+
resources:
|
29
|
+
home: http://rubyworks.github.com/xdg
|
30
|
+
code: http://github.com/rubyworks/xdg
|
31
|
+
repositories: {}
|
32
|
+
|
33
|
+
spec_version: 1.0.0
|
data/APACHE2.txt
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
.
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
203
|
+
|
204
|
+
|
data/{HISTORY → HISTORY.rdoc}
RENAMED
@@ -1,5 +1,19 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 2.0.0 / 2011-06-09
|
4
|
+
|
5
|
+
Major new release is full rewrite of the API, with an eye out for
|
6
|
+
support future XDG standards beyond the base directories. The
|
7
|
+
new API uses a single point of entry `XDG[]` (a shortcut for
|
8
|
+
`XDG::BaseDir[]`).
|
9
|
+
|
10
|
+
Changes:
|
11
|
+
|
12
|
+
* Complete rewrite of API.
|
13
|
+
* Utilize single point of entry interface.
|
14
|
+
* Structure project for future support of more of XDG.
|
15
|
+
|
16
|
+
|
3
17
|
== 1.0.0 / 2009-12-01
|
4
18
|
|
5
19
|
This is major reimplementation of the XDG API to be more flexiable
|
data/README.rdoc
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
= XDG Standards for Ruby
|
2
|
+
|
3
|
+
Author:: Thomas Sawyer
|
4
|
+
Copyright:: (c) 2011 Thomas Sawyer
|
5
|
+
License:: Apache 2.0
|
6
|
+
|
7
|
+
|
8
|
+
== Introduction
|
9
|
+
|
10
|
+
XDG provides an easy to use Ruby library for working with XDG standards.
|
11
|
+
|
12
|
+
Presently, it only supports the XDG Base Directory Standard.
|
13
|
+
|
14
|
+
If your program utilizes user or system-wide support files
|
15
|
+
(e.g. configuration files), you owe it to yourself to checkout
|
16
|
+
the XDG base directory standard.
|
17
|
+
|
18
|
+
You can learn more about the standard at:
|
19
|
+
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
20
|
+
|
21
|
+
|
22
|
+
== Resources
|
23
|
+
|
24
|
+
* {Homepage}[http://rubyworks.github.com/xdg]
|
25
|
+
* {Source Code}[http://github.com/rubyworks/xdg]
|
26
|
+
* {Report an Issue}[http://github.com/rubyworks/xdg/issues]
|
27
|
+
* {Mailing List}[http://googlegroups.com/group.rubyworks-mailinglist]
|
28
|
+
|
29
|
+
|
30
|
+
== How to Use
|
31
|
+
|
32
|
+
For working with XDG base directories, XDG provides a very simple
|
33
|
+
yet flexible interface, `XDG[]`. Let's say you want to work
|
34
|
+
with the $XDG_CONFIG_HOME directory. Simply use:
|
35
|
+
|
36
|
+
XDG['CONFIG_HOME']
|
37
|
+
|
38
|
+
This will give you access to a number of useful methods all tied
|
39
|
+
into the user's personal configuration directory. Some examples:
|
40
|
+
|
41
|
+
XDG['CONFIG_HOME'].glob(pattern)
|
42
|
+
XDG['CONFIG_HOME'].select(pattern){ |path| ... }
|
43
|
+
XDG['CONFIG_HOME'].find(pattern){ |path| ... }
|
44
|
+
|
45
|
+
The same holds true for the other base directories.
|
46
|
+
|
47
|
+
XDG['DATA_HOME']
|
48
|
+
XDG['DATA_DIRS']
|
49
|
+
|
50
|
+
XDG['CACHE_HOME']
|
51
|
+
XDG['CACHE_DIRS']
|
52
|
+
|
53
|
+
By leaving out the last qualifier, XDG will provide an interface
|
54
|
+
that ties into both the `HOME` and `DIRS` paths.
|
55
|
+
|
56
|
+
XDG['DATA']
|
57
|
+
XDG['CONFIG']
|
58
|
+
XDG['CACHE']
|
59
|
+
|
60
|
+
If you know XDG these are pretty much self-explanatory.
|
61
|
+
But see the YARD-based API documentation for further specifics.
|
62
|
+
|
63
|
+
=== Extended Functionality
|
64
|
+
|
65
|
+
The Ruby XDG module also provides extended functionality
|
66
|
+
not part of the standard specification. These extensions are
|
67
|
+
simply add-on functionality deemed useful, or implementations
|
68
|
+
of proposals being discussed for a possible future version of
|
69
|
+
the standard.
|
70
|
+
|
71
|
+
XDG['CONFIG_WORK']
|
72
|
+
XDG['CACHE_WORK']
|
73
|
+
|
74
|
+
See the API documentation to learn more. Note that the extended modules
|
75
|
+
are subject to greater potential for change as they are still being refined.
|
76
|
+
|
77
|
+
=== Base Directory Mixin
|
78
|
+
|
79
|
+
XDG provides a convenient base directory mixin that can provide handy a
|
80
|
+
interface to a classes.
|
81
|
+
|
82
|
+
class MyAppConfig
|
83
|
+
include XDG::BaseDir::Mixin
|
84
|
+
|
85
|
+
def subdirectory
|
86
|
+
'myapp'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
c = MyAppConfig.new
|
91
|
+
|
92
|
+
c.config.home.to_s #=> '~/.config/myapp'
|
93
|
+
|
94
|
+
|
95
|
+
=== Legacy API
|
96
|
+
|
97
|
+
Version 2.0+ of library marks are major departure from the earlier
|
98
|
+
"fluid" notations of previous versions. Where as one used to do:
|
99
|
+
|
100
|
+
XDG.data.home
|
101
|
+
|
102
|
+
With the new API one now does:
|
103
|
+
|
104
|
+
XDG['DATA_HOME']
|
105
|
+
|
106
|
+
This was done for a few reasons, but primarily because it reflects more
|
107
|
+
closely Ruby's interface to the environment variables themselves, e.g.
|
108
|
+
|
109
|
+
ENV['XDG_DATA_HOME']
|
110
|
+
|
111
|
+
If you prefer the older style, a compatibility layer is provided. You will
|
112
|
+
need to load:
|
113
|
+
|
114
|
+
require 'xdg/base_dir/legacy'
|
115
|
+
|
116
|
+
However we STRONGLY RECOMMEND that you do not use the legacy API --use it only
|
117
|
+
if you need to keep some old code working and don't have time to update it at
|
118
|
+
them moment. Sometime in the future the legacy API will be deprecated.
|
119
|
+
|
120
|
+
|
121
|
+
== How to Install
|
122
|
+
|
123
|
+
Using RubyGems:
|
124
|
+
|
125
|
+
$ sudo gem install xdg
|
126
|
+
|
127
|
+
Installing the tarball requires Ruby Setup (see http://rubyworks.github.com/setup).
|
128
|
+
|
129
|
+
$ tar -xvzf xdg-0.5.2
|
130
|
+
$ cd xdg-0.5.2
|
131
|
+
$ sudo setup.rb all
|
132
|
+
|
133
|
+
|
134
|
+
== Development
|
135
|
+
|
136
|
+
GitHub[http://github.com] hosts our {source code}[http://github.com/rubyworks/xdg]
|
137
|
+
and {issue ticket system}[http://github.com/rubyworks/xdg/issues].
|
138
|
+
|
139
|
+
To contribute to the project please fork the repository, ideally, create a new
|
140
|
+
topic branch for your work, and submit a pull request.
|
141
|
+
|
142
|
+
|
143
|
+
== Copyright & License
|
144
|
+
|
145
|
+
Copyright (c) 2008, 2011 Thomas Sawyer
|
146
|
+
|
147
|
+
Distributed under the terms of the Apache 2.0 license.
|
148
|
+
|
149
|
+
See APACHE2.txt file for details.
|
data/lib/xdg.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# = XDG Base Directory Standard
|
1
|
+
# XDG Base Directory Standard
|
4
2
|
#
|
5
3
|
# This provides a conveient library for conforming to the
|
6
4
|
# XDG Base Directory Standard.
|
@@ -26,233 +24,23 @@ require 'rbconfig'
|
|
26
24
|
# The module returns all paths as String.
|
27
25
|
#
|
28
26
|
module XDG
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# Access to data resource locations.
|
40
|
-
#
|
41
|
-
# XDG.data.each{ |dir| ... }
|
42
|
-
#
|
43
|
-
def data(*glob_and_flags, &block)
|
44
|
-
if !glob_and_flags.empty? or block_given?
|
45
|
-
Data.select(*glob_and_flags, &block)
|
46
|
-
else
|
47
|
-
Data
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Access to configuration locations.
|
52
|
-
#
|
53
|
-
# XDG.config.each{ |dir| ... }
|
54
|
-
#
|
55
|
-
def config(*glob_and_flags, &block)
|
56
|
-
if !glob_and_flags.empty? or block_given?
|
57
|
-
Config.select(*glob_and_flags, &block)
|
58
|
-
else
|
59
|
-
Config
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Access to cache locations.
|
64
|
-
#
|
65
|
-
# XDG.cache.each{ |dir| ... }
|
66
|
-
#
|
67
|
-
def cache(*glob_and_flags, &block)
|
68
|
-
if !glob_and_flags.empty? or block_given?
|
69
|
-
Cache.select(*glob_and_flags, &block)
|
70
|
-
else
|
71
|
-
Cache
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Each directory set shares these common methods.
|
76
|
-
#
|
77
|
-
module Common
|
78
|
-
|
79
|
-
# Returns a complete list of directories, starting
|
80
|
-
# with the home location and moving outward.
|
81
|
-
def list
|
82
|
-
[home, *dirs]
|
83
|
-
end
|
84
|
-
|
85
|
-
# Return array of matching files or directories
|
86
|
-
# in any of the resource locations, starting with
|
87
|
-
# the home directory and searching outward into
|
88
|
-
# system directories.
|
89
|
-
#
|
90
|
-
# Unlike #select, this doesn't take a block and each
|
91
|
-
# additional glob argument is treated as a logical-or.
|
92
|
-
#
|
93
|
-
# XDG::Data.glob("stick/*.rb", "stick/*.yaml")
|
94
|
-
#
|
95
|
-
def glob(*glob_and_flags)
|
96
|
-
glob, flags = *parse_arguments(*glob_and_flags)
|
97
|
-
find = []
|
98
|
-
list.each do |dir|
|
99
|
-
glob.each do |pattern|
|
100
|
-
find.concat(Dir.glob(File.join(dir, pattern), flags))
|
101
|
-
end
|
102
|
-
end
|
103
|
-
find.uniq
|
104
|
-
end
|
105
|
-
|
106
|
-
# Return array of matching files or directories
|
107
|
-
# in any of the resource locations, starting with
|
108
|
-
# the home directory and searching outward into
|
109
|
-
# system directories.
|
110
|
-
#
|
111
|
-
# String parameters are joined into a pathname
|
112
|
-
# while Integers and Symbols treated as flags.
|
113
|
-
#
|
114
|
-
# For example, the following are equivalent:
|
115
|
-
#
|
116
|
-
# XDG.data.select('stick/units', File::FNM_CASEFOLD)
|
117
|
-
#
|
118
|
-
# XDG.data.select('stick', 'units', :casefold)
|
119
|
-
#
|
120
|
-
def select(*glob_and_flags, &block)
|
121
|
-
glob, flag = *parse_arguments(*glob_and_flags)
|
122
|
-
find = []
|
123
|
-
list.each do |dir|
|
124
|
-
path = File.join(dir, *glob)
|
125
|
-
hits = Dir.glob(path, flag)
|
126
|
-
hits = hits.select(&block) if block_given?
|
127
|
-
find.concat(hits)
|
128
|
-
end
|
129
|
-
find.uniq
|
130
|
-
end
|
131
|
-
|
132
|
-
# Find a file or directory. This works just like #select
|
133
|
-
# except that it returns the first match found.
|
134
|
-
#
|
135
|
-
# TODO: It would be more efficient to traverse the dirs and use #fnmatch.
|
136
|
-
#
|
137
|
-
def find(*glob_and_flags, &block)
|
138
|
-
glob, flag = *parse_arguments(*glob_and_flags)
|
139
|
-
find = nil
|
140
|
-
list.each do |dir|
|
141
|
-
path = File.join(dir, *glob)
|
142
|
-
hits = Dir.glob(path, flag)
|
143
|
-
hits = hits.select(&block) if block_given?
|
144
|
-
find = hits.first
|
145
|
-
break if find
|
146
|
-
end
|
147
|
-
find
|
148
|
-
end
|
149
|
-
|
150
|
-
private
|
151
|
-
|
152
|
-
def parse_arguments(*glob_and_flags)
|
153
|
-
glob, flags = *glob_and_flags.partition{ |e| String===e }
|
154
|
-
glob = ['**/*'] if glob.empty?
|
155
|
-
flag = flags.inject(0) do |m, f|
|
156
|
-
if Symbol === f
|
157
|
-
m + File::const_get("FNM_#{f.to_s.upcase}")
|
158
|
-
else
|
159
|
-
m + f.to_i
|
160
|
-
end
|
161
|
-
end
|
162
|
-
return glob, flag
|
163
|
-
end
|
164
|
-
|
27
|
+
if RUBY_VERSION > '1.9'
|
28
|
+
require_relative 'xdg/version'
|
29
|
+
require_relative 'xdg/base_dir'
|
30
|
+
require_relative 'xdg/base_dir/extended'
|
31
|
+
require_relative 'xdg/base_dir/mixin'
|
32
|
+
else
|
33
|
+
require 'xdg/version'
|
34
|
+
require 'xdg/base_dir'
|
35
|
+
require 'xdg/base_dir/extended'
|
36
|
+
require 'xdg/base_dir/mixin'
|
165
37
|
end
|
166
38
|
|
167
|
-
# = DATA LOCATIONS
|
168
39
|
#
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
# Location of personal data directory.
|
173
|
-
def home
|
174
|
-
@home ||= (
|
175
|
-
File.expand_path(
|
176
|
-
ENV['XDG_DATA_HOME'] || File.join(XDG.home, '.local', 'share')
|
177
|
-
)
|
178
|
-
)
|
179
|
-
end
|
180
|
-
|
181
|
-
# List of shared data directores.
|
182
|
-
def dirs
|
183
|
-
@dirs ||= (
|
184
|
-
dirs = ENV['XDG_DATA_DIRS'].split(/[:;]/)
|
185
|
-
if dirs.empty?
|
186
|
-
#dirs = [ Config::CONFIG['localdatadir'], Config::CONFIG['datadir'] ]
|
187
|
-
dirs = Resource.dirs.map{ |d| File.join(d, 'share') }
|
188
|
-
end
|
189
|
-
dirs = dirs.map{ |d| File.expand_path(d) }.uniq
|
190
|
-
dirs = dirs.select{ |d| File.directory?(d) }
|
191
|
-
dirs
|
192
|
-
)
|
193
|
-
end
|
194
|
-
|
195
|
-
extend self
|
40
|
+
def self.[](*env_path)
|
41
|
+
BaseDir.new(*env_path)
|
196
42
|
end
|
43
|
+
end
|
197
44
|
|
198
|
-
|
199
|
-
|
200
|
-
module Config
|
201
|
-
include Common
|
202
|
-
extend self
|
203
|
-
|
204
|
-
# Location of personal config directory.
|
205
|
-
def home
|
206
|
-
@home ||= (
|
207
|
-
File.expand_path(
|
208
|
-
ENV['XDG_CONFIG_HOME'] || File.join(XDG.home, '.config')
|
209
|
-
)
|
210
|
-
)
|
211
|
-
end
|
212
|
-
|
213
|
-
# List of shared config directories.
|
214
|
-
def dirs
|
215
|
-
@dirs ||= (
|
216
|
-
dirs = ENV['XDG_CONFIG_DIRS'].to_s.split(/[:;]/)
|
217
|
-
if dirs.empty?
|
218
|
-
#dirs = ['etc/xdg', 'etc']
|
219
|
-
sysconfdir = ::Config::CONFIG['sysconfdir']
|
220
|
-
dirs = [ File.join(sysconfdir, 'xdg'), sysconfdir ]
|
221
|
-
end
|
222
|
-
dirs = dirs.map{ |d| File.expand_path(d) }.uniq
|
223
|
-
dirs = dirs.select{ |d| File.directory?(d) }
|
224
|
-
dirs
|
225
|
-
)
|
226
|
-
end
|
227
|
-
|
228
|
-
extend self
|
229
|
-
end
|
230
|
-
|
231
|
-
# = CACHE LOCATIONS
|
232
|
-
#
|
233
|
-
module Cache
|
234
|
-
include Common
|
235
|
-
|
236
|
-
# Location of user's personal cache directory.
|
237
|
-
def home
|
238
|
-
@home ||= (
|
239
|
-
File.expand_path(
|
240
|
-
ENV['XDG_CACHE_HOME'] || File.join(XDG.home, '.cache')
|
241
|
-
)
|
242
|
-
)
|
243
|
-
end
|
244
|
-
|
245
|
-
# Serves as a no-op, since there are no common cache directories
|
246
|
-
# defined by the XDG standard. (Though one might argue that
|
247
|
-
# <tt>tmp/</tt> is one.)
|
248
|
-
def dirs
|
249
|
-
@dirs ||= []
|
250
|
-
end
|
251
|
-
|
252
|
-
extend self
|
253
|
-
end
|
254
|
-
|
255
|
-
end # module XDG
|
256
|
-
|
257
|
-
# Copyright (c) 2008,2009 Thomas Sawyer
|
258
|
-
# Distributed under the terms of the LGPL v3.
|
45
|
+
# Copyright (c) 2008,2011 Thomas Sawyer
|
46
|
+
# Distributed under the terms of the APACHE 2.0 license.
|