data_paths 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.specopts +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +41 -0
- data/data_paths.gemspec +75 -0
- data/lib/data_paths/data_paths.rb +21 -0
- data/lib/data_paths/finders.rb +195 -0
- data/lib/data_paths/methods.rb +70 -0
- data/lib/data_paths/version.rb +4 -0
- data/lib/data_paths.rb +3 -0
- data/spec/classes/data_class.rb +8 -0
- data/spec/data_paths_spec.rb +26 -0
- data/spec/finders_spec.rb +39 -0
- data/spec/helpers/data.rb +12 -0
- data/spec/helpers/data1/dir/two.txt +0 -0
- data/spec/helpers/data1/one.txt +0 -0
- data/spec/helpers/data2/dir/two.txt +0 -0
- data/spec/methods_examples.rb +30 -0
- data/spec/spec_helper.rb +5 -0
- metadata +117 -0
data/.gitignore
ADDED
data/.specopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format specdoc
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title 'DataPaths Documentation' --protected --files ChangeLog.md,LICENSE.txt
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
### 0.2.1 / 2010-04-13
|
2
|
+
|
3
|
+
* Minor bug-fix in {DataPaths::Methods#unregister_data_dirs!}.
|
4
|
+
|
5
|
+
### 0.2.0 / 2010-04-13
|
6
|
+
|
7
|
+
* Renamed the static_paths gem to data_paths, since the `data/` directory
|
8
|
+
is the prefered directory for storing static-content in Ruby libraries.
|
9
|
+
|
10
|
+
### 0.1.0 / 2010-01-22
|
11
|
+
|
12
|
+
* Initial release:
|
13
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2010 Hal Brodigan
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
'Software'), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# data_paths
|
2
|
+
|
3
|
+
* http://data_paths.rubyforge.org/
|
4
|
+
* http://github.com/postmodern/data_paths
|
5
|
+
* http://github.com/postmodern/data_paths/issues
|
6
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
7
|
+
|
8
|
+
## DESCRIPTION:
|
9
|
+
|
10
|
+
DataPaths is a library to manage the paths of directories containing
|
11
|
+
static-content across multiple libraries.
|
12
|
+
|
13
|
+
For example, DataPaths can manage the `data/` directories of
|
14
|
+
multiple RubyGems, in much the same way RubyGems manages the paths of
|
15
|
+
`lib/` directories using `$LOAD_PATH`.
|
16
|
+
|
17
|
+
## FEATURES:
|
18
|
+
|
19
|
+
* Allows libraries to register static-content directories using the
|
20
|
+
`register_data_dir` class or instance method.
|
21
|
+
* Allows libraries to unregister a single path using
|
22
|
+
`unregister_data_dir` or all paths registered by that library with
|
23
|
+
`unregister_data_dirs`.
|
24
|
+
* Provides helper methods in {DataPaths::Finders} for searching through
|
25
|
+
the registered static-content directories.
|
26
|
+
* Does not use global variables.
|
27
|
+
|
28
|
+
## EXAMPLES:
|
29
|
+
|
30
|
+
Register a directory containing static-content:
|
31
|
+
|
32
|
+
require 'data_paths'
|
33
|
+
|
34
|
+
module MyLibrary
|
35
|
+
include DataPaths
|
36
|
+
|
37
|
+
# define the data dir(s)
|
38
|
+
register_data_dir File.join(File.dirname(__FILE__),'..','..','data')
|
39
|
+
end
|
40
|
+
|
41
|
+
List previously registered static-content directories:
|
42
|
+
|
43
|
+
# all data directories
|
44
|
+
DataPaths.paths
|
45
|
+
# => #<Set: {...}>
|
46
|
+
|
47
|
+
# the data directories registeed in MyLibrary
|
48
|
+
MyLibrary.data_paths
|
49
|
+
# => #<Set: {...}>
|
50
|
+
|
51
|
+
# list data directories registered in an object
|
52
|
+
lib = MyLibrary.new
|
53
|
+
lib.register_data_dir File.join('path','to','data')
|
54
|
+
|
55
|
+
lib.data_paths
|
56
|
+
# => #<Set: {...}>
|
57
|
+
|
58
|
+
Using {DataPaths::Finders} to access content from within the
|
59
|
+
static-content directories:
|
60
|
+
|
61
|
+
module MyLibrary
|
62
|
+
class UsesContent
|
63
|
+
|
64
|
+
include DataPaths::Finders
|
65
|
+
|
66
|
+
def index
|
67
|
+
find_data_file('index.html')
|
68
|
+
end
|
69
|
+
|
70
|
+
def file_dirs
|
71
|
+
all_data_dirs('extra')
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
## INSTALL:
|
78
|
+
|
79
|
+
$ sudo gem install data_paths
|
80
|
+
|
81
|
+
## LICENSE:
|
82
|
+
|
83
|
+
See {file:LICENSE.txt} for license information.
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require './lib/data_paths/version.rb'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = 'data_paths'
|
9
|
+
gem.version = DataPaths::VERSION
|
10
|
+
gem.summary = %Q{DataPaths is a library to manage the paths of directories containing static-content across multiple libraries.}
|
11
|
+
gem.description = %Q{DataPaths is a library to manage the paths of directories containing static-content across multiple libraries. For example, DataPaths can manage the `data/` directories of multiple RubyGems, in much the same way RubyGems manages the paths of `lib/` directories using `$LOAD_PATH`.}
|
12
|
+
gem.email = 'postmodern.mod3@gmail.com'
|
13
|
+
gem.homepage = 'http://github.com/postmodern/data_paths'
|
14
|
+
gem.authors = ['Postmodern']
|
15
|
+
gem.add_development_dependency 'rspec', '>= 1.3.0'
|
16
|
+
gem.add_development_dependency 'yard', '>= 0.5.3'
|
17
|
+
gem.has_rdoc = 'yard'
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs += ['lib', 'spec']
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
spec.spec_opts = ['--options', '.specopts']
|
28
|
+
end
|
29
|
+
|
30
|
+
task :spec => :check_dependencies
|
31
|
+
task :default => :spec
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'yard'
|
35
|
+
|
36
|
+
YARD::Rake::YardocTask.new
|
37
|
+
rescue LoadError
|
38
|
+
task :yard do
|
39
|
+
abort "YARD is not available. In order to run yard, you must: gem install yard"
|
40
|
+
end
|
41
|
+
end
|
data/data_paths.gemspec
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{data_paths}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Postmodern"]
|
12
|
+
s.date = %q{2010-04-13}
|
13
|
+
s.description = %q{DataPaths is a library to manage the paths of directories containing static-content across multiple libraries. For example, DataPaths can manage the `data/` directories of multiple RubyGems, in much the same way RubyGems manages the paths of `lib/` directories using `$LOAD_PATH`.}
|
14
|
+
s.email = %q{postmodern.mod3@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"ChangeLog.md",
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
".specopts",
|
23
|
+
".yardopts",
|
24
|
+
"ChangeLog.md",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"data_paths.gemspec",
|
29
|
+
"lib/data_paths.rb",
|
30
|
+
"lib/data_paths/data_paths.rb",
|
31
|
+
"lib/data_paths/finders.rb",
|
32
|
+
"lib/data_paths/methods.rb",
|
33
|
+
"lib/data_paths/version.rb",
|
34
|
+
"spec/classes/data_class.rb",
|
35
|
+
"spec/data_paths_spec.rb",
|
36
|
+
"spec/finders_spec.rb",
|
37
|
+
"spec/helpers/data.rb",
|
38
|
+
"spec/helpers/data1/dir/two.txt",
|
39
|
+
"spec/helpers/data1/one.txt",
|
40
|
+
"spec/helpers/data2/dir/two.txt",
|
41
|
+
"spec/methods_examples.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
s.has_rdoc = %q{yard}
|
45
|
+
s.homepage = %q{http://github.com/postmodern/data_paths}
|
46
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
47
|
+
s.require_paths = ["lib"]
|
48
|
+
s.rubygems_version = %q{1.3.6}
|
49
|
+
s.summary = %q{DataPaths is a library to manage the paths of directories containing static-content across multiple libraries.}
|
50
|
+
s.test_files = [
|
51
|
+
"spec/finders_spec.rb",
|
52
|
+
"spec/methods_examples.rb",
|
53
|
+
"spec/spec_helper.rb",
|
54
|
+
"spec/helpers/data.rb",
|
55
|
+
"spec/classes/data_class.rb",
|
56
|
+
"spec/data_paths_spec.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
|
65
|
+
s.add_development_dependency(%q<yard>, [">= 0.5.3"])
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
68
|
+
s.add_dependency(%q<yard>, [">= 0.5.3"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
72
|
+
s.add_dependency(%q<yard>, [">= 0.5.3"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'data_paths/methods'
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module DataPaths
|
6
|
+
include Methods
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.extend Methods
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# The registered `data/` directories.
|
14
|
+
#
|
15
|
+
# @return [Set]
|
16
|
+
# The directories which contain static content.
|
17
|
+
#
|
18
|
+
def DataPaths.paths
|
19
|
+
@@data_paths ||= Set[]
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'data_paths/data_paths'
|
2
|
+
|
3
|
+
require 'enumerator'
|
4
|
+
|
5
|
+
module DataPaths
|
6
|
+
module Finders
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
#
|
10
|
+
# Passes all existing data paths for the specified path,
|
11
|
+
# within the data directories, to the given block.
|
12
|
+
#
|
13
|
+
# @param [String] path
|
14
|
+
# The path to search for in all data directories.
|
15
|
+
#
|
16
|
+
# @yield [potential_path]
|
17
|
+
# The given block will be passed every existing combination of the
|
18
|
+
# given path and the data directories.
|
19
|
+
#
|
20
|
+
# @yieldparam [String] potential_path
|
21
|
+
# An existing data path.
|
22
|
+
#
|
23
|
+
def each_data_path(path,&block)
|
24
|
+
DataPaths.paths.each do |dir|
|
25
|
+
full_path = File.join(dir,path)
|
26
|
+
|
27
|
+
block.call(full_path) if File.exists?(full_path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Searches for the given path within any data directory.
|
33
|
+
#
|
34
|
+
# @param [String] path
|
35
|
+
# The path to search for.
|
36
|
+
#
|
37
|
+
# @return [String, nil]
|
38
|
+
# Returns the first valid match for the given path within a data
|
39
|
+
# directory. Returns `nil` if the given path could not be found
|
40
|
+
# in any data directory.
|
41
|
+
#
|
42
|
+
def find_data_path(path)
|
43
|
+
enum_for(:each_data_path,path).first
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Searches for a file at the given path, within any data directory.
|
48
|
+
#
|
49
|
+
# @param [String] path
|
50
|
+
# The file path to search for.
|
51
|
+
#
|
52
|
+
# @return [String, nil]
|
53
|
+
# Returns the first valid file at the given path within a data
|
54
|
+
# directory. Returns `nil` if the given path could not be found
|
55
|
+
# in any data directory.
|
56
|
+
#
|
57
|
+
def find_data_file(path)
|
58
|
+
each_data_path(path) do |full_path|
|
59
|
+
return full_path if File.file?(full_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Searches for a directory at the given path, within any data
|
67
|
+
# directory.
|
68
|
+
#
|
69
|
+
# @param [String] path
|
70
|
+
# The directory path to search for.
|
71
|
+
#
|
72
|
+
# @return [String, nil]
|
73
|
+
# Returns the first valid directory at the given path within a
|
74
|
+
# data directory. Returns `nil` if the given path could not be
|
75
|
+
# found in any data directory.
|
76
|
+
#
|
77
|
+
def find_data_dir(path)
|
78
|
+
each_data_path(path) do |full_path|
|
79
|
+
return full_path if File.directory?(full_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
return nil
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Finds all occurrences of a given path, within all data directories.
|
87
|
+
#
|
88
|
+
# @param [String] path
|
89
|
+
# The path to search for.
|
90
|
+
#
|
91
|
+
# @return [Array<String>]
|
92
|
+
# The occurrences of the given path within all data directories.
|
93
|
+
#
|
94
|
+
def all_data_paths(path)
|
95
|
+
enum_for(:each_data_path,path).to_a
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# Finds all occurrences of a given file path, within all data
|
100
|
+
# directories.
|
101
|
+
#
|
102
|
+
# @param [String] path
|
103
|
+
# The file path to search for.
|
104
|
+
#
|
105
|
+
# @yield [data_file]
|
106
|
+
# If a block is given, it will be passed every found path.
|
107
|
+
#
|
108
|
+
# @yieldparam [String] data_file
|
109
|
+
# The path of a file within a data directory.
|
110
|
+
#
|
111
|
+
# @return [Array<String>]
|
112
|
+
# The occurrences of the given file path within all data
|
113
|
+
# directories.
|
114
|
+
#
|
115
|
+
def each_data_file(path,&block)
|
116
|
+
each_data_path(path) do |full_path|
|
117
|
+
block.call(full_path) if File.file?(full_path)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
#
|
123
|
+
# Finds all occurrences of a given file path, within all data
|
124
|
+
# directories.
|
125
|
+
#
|
126
|
+
# @param [String] path
|
127
|
+
# The file path to search for.
|
128
|
+
#
|
129
|
+
# @return [Array<String>]
|
130
|
+
# The occurrences of the given file path within all data
|
131
|
+
# directories.
|
132
|
+
#
|
133
|
+
def all_data_files(path)
|
134
|
+
enum_for(:each_data_file,path).to_a
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Finds all occurrences of a given directory path, within all data
|
139
|
+
# directories.
|
140
|
+
#
|
141
|
+
# @param [String] path
|
142
|
+
# The directory path to search for.
|
143
|
+
#
|
144
|
+
# @yield [data_dir]
|
145
|
+
# If a block is given, it will be passed every found path.
|
146
|
+
#
|
147
|
+
# @yieldparam [String] data_dir
|
148
|
+
# The path of a directory within a data directory.
|
149
|
+
#
|
150
|
+
# @return [Array<String>]
|
151
|
+
# The occurrences of the given directory path within all data
|
152
|
+
# directories.
|
153
|
+
#
|
154
|
+
def each_data_dir(path,&block)
|
155
|
+
each_data_path(path) do |full_path|
|
156
|
+
block.call(full_path) if File.directory?(full_path)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# Finds all occurrences of a given directory path, within all data
|
162
|
+
# directories.
|
163
|
+
#
|
164
|
+
# @param [String] path
|
165
|
+
# The directory path to search for.
|
166
|
+
#
|
167
|
+
# @return [Array<String>]
|
168
|
+
# The occurrences of the given directory path within all data
|
169
|
+
# directories.
|
170
|
+
#
|
171
|
+
def all_data_dirs(path)
|
172
|
+
enum_for(:each_data_dir,path).to_a
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Finds all paths that match a given pattern, within all data
|
177
|
+
# directories.
|
178
|
+
#
|
179
|
+
# @param [String] pattern
|
180
|
+
# The path glob pattern to search with.
|
181
|
+
#
|
182
|
+
# @return [Array<String>]
|
183
|
+
# The matching paths found within all data directories.
|
184
|
+
#
|
185
|
+
def data_glob(pattern)
|
186
|
+
paths = []
|
187
|
+
|
188
|
+
DataPaths.paths.each do |path|
|
189
|
+
paths += Dir[File.join(path,pattern)]
|
190
|
+
end
|
191
|
+
|
192
|
+
return paths
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module DataPaths
|
4
|
+
module Methods
|
5
|
+
#
|
6
|
+
# The directories registered within a specific module or class.
|
7
|
+
#
|
8
|
+
# @return [Set]
|
9
|
+
# The directories registered so far.
|
10
|
+
#
|
11
|
+
def data_paths
|
12
|
+
@data_paths ||= Set[]
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Registers a path as a data directory.
|
17
|
+
#
|
18
|
+
# @param [String] path
|
19
|
+
# The path to add to {DataPaths.paths}.
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
# The fully qualified form of the specified path.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# register_data_dir File.join(File.dirname(__FILE__),'..','..','..','data')
|
26
|
+
#
|
27
|
+
# @raise [RuntimeError]
|
28
|
+
# The specified path is not a directory.
|
29
|
+
#
|
30
|
+
def register_data_dir(path)
|
31
|
+
path = File.expand_path(path)
|
32
|
+
|
33
|
+
unless File.directory?(path)
|
34
|
+
raise(RuntimeError,"#{path.dump} must be a directory")
|
35
|
+
end
|
36
|
+
|
37
|
+
self.data_paths << path
|
38
|
+
|
39
|
+
DataPaths.paths << path
|
40
|
+
return path
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Unregisters any matching data directories.
|
45
|
+
#
|
46
|
+
# @param [String] path
|
47
|
+
# The path to unregistere.
|
48
|
+
#
|
49
|
+
# @return [true]
|
50
|
+
#
|
51
|
+
def unregister_data_dir!(path)
|
52
|
+
path = File.expand_path(path)
|
53
|
+
|
54
|
+
self.data_paths.reject! { |dir| dir == path }
|
55
|
+
DataPaths.paths.reject! { |dir| dir == path }
|
56
|
+
return true
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Unregisters all previously registered data directories.
|
61
|
+
#
|
62
|
+
# @return [true]
|
63
|
+
#
|
64
|
+
def unregister_data_dirs!
|
65
|
+
DataPaths.paths.reject! { |dir| self.data_paths.include?(dir) }
|
66
|
+
self.data_paths.clear
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/data_paths.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'data_paths/data_paths'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'helpers/data'
|
5
|
+
require 'classes/data_class'
|
6
|
+
require 'methods_examples'
|
7
|
+
|
8
|
+
describe DataPaths do
|
9
|
+
describe "instance methods" do
|
10
|
+
include DataPaths
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
@context = self
|
14
|
+
end
|
15
|
+
|
16
|
+
it_should_behave_like "Methods"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "class methods" do
|
20
|
+
before(:all) do
|
21
|
+
@context = DataClass
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_behave_like "Methods"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'data_paths/finders'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'helpers/data'
|
5
|
+
|
6
|
+
describe DataPaths::Finders do
|
7
|
+
before(:all) do
|
8
|
+
@example = DataClass.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should find a file" do
|
12
|
+
@example.find_data_file('one.txt').should == File.join(Helpers::DATA_DIRS[0],'one.txt')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should find a directory" do
|
16
|
+
@example.find_data_dir('dir').should == File.join(Helpers::DATA_DIRS[0],'dir')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should find all matching files" do
|
20
|
+
@example.all_data_files('dir/two.txt').should == [
|
21
|
+
File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
|
22
|
+
File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should find all matching directories" do
|
27
|
+
@example.all_data_dirs('dir').should == [
|
28
|
+
File.join(Helpers::DATA_DIRS[0],'dir'),
|
29
|
+
File.join(Helpers::DATA_DIRS[1],'dir')
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should find all paths matching a pattern" do
|
34
|
+
@example.data_glob('*/*.txt').should == [
|
35
|
+
File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
|
36
|
+
File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'data_paths/data_paths'
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
include DataPaths
|
5
|
+
|
6
|
+
DATA_DIRS = [
|
7
|
+
File.expand_path(File.join(File.dirname(__FILE__),'data1')),
|
8
|
+
File.expand_path(File.join(File.dirname(__FILE__),'data2')),
|
9
|
+
]
|
10
|
+
|
11
|
+
DATA_DIRS.each { |dir| register_data_dir dir }
|
12
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'data_paths/data_paths'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'helpers/data'
|
5
|
+
|
6
|
+
shared_examples_for "Methods" do
|
7
|
+
before(:all) do
|
8
|
+
Helpers::DATA_DIRS.each do |dir|
|
9
|
+
@context.register_data_dir dir
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should list data directories" do
|
14
|
+
Helpers::DATA_DIRS.each do |dir|
|
15
|
+
@context.data_paths.should include(dir)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should prevent the addition of non-existant directories" do
|
20
|
+
lambda {
|
21
|
+
@context.register_data_dir 'lol'
|
22
|
+
}.should raise_error(RuntimeError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should prevent the addition of non-directories" do
|
26
|
+
lambda {
|
27
|
+
@context.register_data_dir __FILE__
|
28
|
+
}.should raise_error(RuntimeError)
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: data_paths
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Postmodern
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-13 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: 1.3.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: yard
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 5
|
44
|
+
- 3
|
45
|
+
version: 0.5.3
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: DataPaths is a library to manage the paths of directories containing static-content across multiple libraries. For example, DataPaths can manage the `data/` directories of multiple RubyGems, in much the same way RubyGems manages the paths of `lib/` directories using `$LOAD_PATH`.
|
49
|
+
email: postmodern.mod3@gmail.com
|
50
|
+
executables: []
|
51
|
+
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files:
|
55
|
+
- ChangeLog.md
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- .specopts
|
61
|
+
- .yardopts
|
62
|
+
- ChangeLog.md
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- data_paths.gemspec
|
67
|
+
- lib/data_paths.rb
|
68
|
+
- lib/data_paths/data_paths.rb
|
69
|
+
- lib/data_paths/finders.rb
|
70
|
+
- lib/data_paths/methods.rb
|
71
|
+
- lib/data_paths/version.rb
|
72
|
+
- spec/classes/data_class.rb
|
73
|
+
- spec/data_paths_spec.rb
|
74
|
+
- spec/finders_spec.rb
|
75
|
+
- spec/helpers/data.rb
|
76
|
+
- spec/helpers/data1/dir/two.txt
|
77
|
+
- spec/helpers/data1/one.txt
|
78
|
+
- spec/helpers/data2/dir/two.txt
|
79
|
+
- spec/methods_examples.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
has_rdoc: yard
|
82
|
+
homepage: http://github.com/postmodern/data_paths
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options:
|
87
|
+
- --charset=UTF-8
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.3.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: DataPaths is a library to manage the paths of directories containing static-content across multiple libraries.
|
111
|
+
test_files:
|
112
|
+
- spec/finders_spec.rb
|
113
|
+
- spec/methods_examples.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
- spec/helpers/data.rb
|
116
|
+
- spec/classes/data_class.rb
|
117
|
+
- spec/data_paths_spec.rb
|