data_paths 0.2.1 → 0.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.rspec +1 -0
- data/ChangeLog.md +17 -0
- data/LICENSE.txt +1 -3
- data/README.md +19 -18
- data/Rakefile +21 -26
- data/data_paths.gemspec +11 -71
- data/gemspec.yml +18 -0
- data/lib/data_paths/data_paths.rb +36 -4
- data/lib/data_paths/finders.rb +80 -33
- data/lib/data_paths/methods.rb +50 -21
- data/lib/data_paths/version.rb +1 -1
- data/spec/data_paths_spec.rb +2 -8
- data/spec/finders_spec.rb +12 -9
- data/spec/helpers/data.rb +1 -1
- data/spec/methods_examples.rb +4 -4
- data/spec/spec_helper.rb +2 -3
- metadata +37 -44
- data/.gitignore +0 -8
- data/.specopts +0 -1
data/.gemtest
ADDED
File without changes
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
### 0.3.0 / 2011-05-14
|
2
|
+
|
3
|
+
* Added {DataPaths::Finders#load_yaml_file}.
|
4
|
+
* Added {DataPaths::Finders#load_yaml_files}.
|
5
|
+
* Added {DataPaths::Finders#glob_data_paths}.
|
6
|
+
* Renamed `DataPaths::Methods#register_data_dir` to
|
7
|
+
{DataPaths::Methods#register_data_path}.
|
8
|
+
* Renamed `DataPaths::Methods#unregister_data_dir` to
|
9
|
+
{DataPaths::Methods#unregister_data_path}.
|
10
|
+
* Renamed `DataPaths::Methods#unregister_data_dirs` to
|
11
|
+
{DataPaths::Methods#unregister_data_paths}.
|
12
|
+
* Renamed `DataPaths.unregister!` to {DataPaths.unregister}.
|
13
|
+
* Changed {DataPaths.paths} to be an `Array`, so order of the registered
|
14
|
+
paths is preserved.
|
15
|
+
* Fixed a bug where {DataPaths::Finders} was needlessly including
|
16
|
+
`Enumerable`.
|
17
|
+
|
1
18
|
### 0.2.1 / 2010-04-13
|
2
19
|
|
3
20
|
* Minor bug-fix in {DataPaths::Methods#unregister_data_dirs!}.
|
data/LICENSE.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
Copyright (c) 2010 Hal Brodigan
|
1
|
+
Copyright (c) 2011 Hal Brodigan
|
3
2
|
|
4
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
4
|
a copy of this software and associated documentation files (the
|
@@ -19,4 +18,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
18
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
19
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
20
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# data_paths
|
2
2
|
|
3
|
-
* http://
|
4
|
-
* http://github.com/postmodern/data_paths
|
5
|
-
* http://
|
6
|
-
*
|
3
|
+
* [Source](http://github.com/postmodern/data_paths)
|
4
|
+
* [Issues](http://github.com/postmodern/data_paths/issues)
|
5
|
+
* [Documentation](http://rubydoc.info/gems/data_paths/frames)
|
6
|
+
* [Email](mailto:postmodern.mod3 at gmail.com)
|
7
7
|
|
8
|
-
##
|
8
|
+
## Description
|
9
9
|
|
10
10
|
DataPaths is a library to manage the paths of directories containing
|
11
11
|
static-content across multiple libraries.
|
@@ -14,18 +14,18 @@ For example, DataPaths can manage the `data/` directories of
|
|
14
14
|
multiple RubyGems, in much the same way RubyGems manages the paths of
|
15
15
|
`lib/` directories using `$LOAD_PATH`.
|
16
16
|
|
17
|
-
##
|
17
|
+
## Features
|
18
18
|
|
19
19
|
* Allows libraries to register static-content directories using the
|
20
|
-
`
|
20
|
+
`register_data_path` class or instance method.
|
21
21
|
* Allows libraries to unregister a single path using
|
22
|
-
`
|
23
|
-
`
|
22
|
+
`unregister_data_path` or all paths registered by that library with
|
23
|
+
`unregister_data_paths`.
|
24
24
|
* Provides helper methods in {DataPaths::Finders} for searching through
|
25
25
|
the registered static-content directories.
|
26
26
|
* Does not use global variables.
|
27
27
|
|
28
|
-
##
|
28
|
+
## Examples
|
29
29
|
|
30
30
|
Register a directory containing static-content:
|
31
31
|
|
@@ -35,25 +35,25 @@ Register a directory containing static-content:
|
|
35
35
|
include DataPaths
|
36
36
|
|
37
37
|
# define the data dir(s)
|
38
|
-
|
38
|
+
register_data_path File.join(File.dirname(__FILE__),'..','..','data')
|
39
39
|
end
|
40
40
|
|
41
41
|
List previously registered static-content directories:
|
42
42
|
|
43
43
|
# all data directories
|
44
44
|
DataPaths.paths
|
45
|
-
# =>
|
45
|
+
# => [...]
|
46
46
|
|
47
47
|
# the data directories registeed in MyLibrary
|
48
48
|
MyLibrary.data_paths
|
49
|
-
# =>
|
49
|
+
# => [...]
|
50
50
|
|
51
51
|
# list data directories registered in an object
|
52
52
|
lib = MyLibrary.new
|
53
|
-
lib.
|
53
|
+
lib.register_data_path File.join('path','to','data')
|
54
54
|
|
55
55
|
lib.data_paths
|
56
|
-
# =>
|
56
|
+
# => [...]
|
57
57
|
|
58
58
|
Using {DataPaths::Finders} to access content from within the
|
59
59
|
static-content directories:
|
@@ -74,11 +74,12 @@ static-content directories:
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
##
|
77
|
+
## Install
|
78
78
|
|
79
79
|
$ sudo gem install data_paths
|
80
80
|
|
81
|
-
##
|
81
|
+
## Copyright
|
82
82
|
|
83
|
-
|
83
|
+
Copyright (c) 2011 Hal Brodigan
|
84
84
|
|
85
|
+
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -1,41 +1,36 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
require './lib/data_paths/version.rb'
|
4
3
|
|
5
4
|
begin
|
6
|
-
|
7
|
-
|
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
|
5
|
+
gem 'ore-tasks', '~> 0.4'
|
6
|
+
require 'ore/tasks'
|
22
7
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
spec.spec_opts = ['--options', '.specopts']
|
8
|
+
Ore::Tasks.new
|
9
|
+
rescue LoadError => e
|
10
|
+
STDERR.puts e.message
|
11
|
+
STDERR.puts "Run `gem install ore-tasks` to install 'ore/tasks'."
|
28
12
|
end
|
29
13
|
|
30
|
-
|
14
|
+
begin
|
15
|
+
gem 'rspec', '~> 2.4'
|
16
|
+
require 'rspec/core/rake_task'
|
17
|
+
|
18
|
+
RSpec::Core::RakeTask.new
|
19
|
+
rescue LoadError => e
|
20
|
+
task :spec do
|
21
|
+
abort "Please run `gem install rspec` to install RSpec."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
task :test => :spec
|
31
25
|
task :default => :spec
|
32
26
|
|
33
27
|
begin
|
28
|
+
gem 'yard', '~> 0.6.0'
|
34
29
|
require 'yard'
|
35
30
|
|
36
|
-
YARD::Rake::YardocTask.new
|
37
|
-
rescue LoadError
|
31
|
+
YARD::Rake::YardocTask.new
|
32
|
+
rescue LoadError => e
|
38
33
|
task :yard do
|
39
|
-
abort "
|
34
|
+
abort "Please run `gem install yard` to install YARD."
|
40
35
|
end
|
41
36
|
end
|
data/data_paths.gemspec
CHANGED
@@ -1,75 +1,15 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
"
|
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"])
|
3
|
+
begin
|
4
|
+
Ore::Specification.new do |gemspec|
|
5
|
+
# custom logic here
|
6
|
+
end
|
7
|
+
rescue NameError
|
8
|
+
begin
|
9
|
+
require 'ore/specification'
|
10
|
+
retry
|
11
|
+
rescue LoadError
|
12
|
+
STDERR.puts "The 'data_paths.gemspec' file requires Ore."
|
13
|
+
STDERR.puts "Run `gem install ore-core` to install Ore."
|
73
14
|
end
|
74
15
|
end
|
75
|
-
|
data/gemspec.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
name: data_paths
|
2
|
+
summary: DataPaths is a library to manage multiple data/ directories.
|
3
|
+
description:
|
4
|
+
DataPaths is a library to manage the paths of directories containing
|
5
|
+
static-content across multiple libraries. For example, DataPaths can
|
6
|
+
manage the `data/` directories of multiple RubyGems, in much the same way
|
7
|
+
RubyGems manages the paths of `lib/` directories using `$LOAD_PATH`.
|
8
|
+
|
9
|
+
license: MIT
|
10
|
+
authors: Postmodern
|
11
|
+
email: postmodern.mod3@gmail.com
|
12
|
+
homepage: http://github.com/postmodern/data_paths
|
13
|
+
has_yard: true
|
14
|
+
|
15
|
+
development_dependencies:
|
16
|
+
ore-tasks: ~> 0.4
|
17
|
+
rspec: ~> 2.4
|
18
|
+
yard: ~> 0.6.0
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'data_paths/methods'
|
2
2
|
|
3
|
-
require 'set'
|
4
|
-
|
5
3
|
module DataPaths
|
6
4
|
include Methods
|
7
5
|
|
@@ -12,10 +10,44 @@ module DataPaths
|
|
12
10
|
#
|
13
11
|
# The registered `data/` directories.
|
14
12
|
#
|
15
|
-
# @return [
|
13
|
+
# @return [Array<String>]
|
16
14
|
# The directories which contain static content.
|
17
15
|
#
|
18
16
|
def DataPaths.paths
|
19
|
-
|
17
|
+
@data_paths ||= []
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Registers a `data/` directory.
|
22
|
+
#
|
23
|
+
# @return [String]
|
24
|
+
# The registered `data/` directory.
|
25
|
+
#
|
26
|
+
# @raise [RuntimeError]
|
27
|
+
# The given path was not a directory.
|
28
|
+
#
|
29
|
+
# @since 0.3.0
|
30
|
+
#
|
31
|
+
def DataPaths.register(path)
|
32
|
+
path = File.expand_path(path)
|
33
|
+
|
34
|
+
unless File.directory?(path)
|
35
|
+
raise("#{path.dump} must be a directory")
|
36
|
+
end
|
37
|
+
|
38
|
+
paths << path unless paths.include?(path)
|
39
|
+
return path
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Unregisters a previously registered `data/` directory.
|
44
|
+
#
|
45
|
+
# @return [String]
|
46
|
+
# The unregistered `data/` directory.
|
47
|
+
#
|
48
|
+
# @since 0.3.0
|
49
|
+
#
|
50
|
+
def DataPaths.unregister(path)
|
51
|
+
paths.delete(File.expand_path(path))
|
20
52
|
end
|
21
53
|
end
|
data/lib/data_paths/finders.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'data_paths/data_paths'
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'yaml'
|
4
4
|
|
5
5
|
module DataPaths
|
6
6
|
module Finders
|
7
|
-
include Enumerable
|
8
|
-
|
9
7
|
#
|
10
8
|
# Passes all existing data paths for the specified path,
|
11
9
|
# within the data directories, to the given block.
|
@@ -20,11 +18,16 @@ module DataPaths
|
|
20
18
|
# @yieldparam [String] potential_path
|
21
19
|
# An existing data path.
|
22
20
|
#
|
23
|
-
|
21
|
+
# @return [Enumerator]
|
22
|
+
# If no block is given, an Enumerator object will be returned.
|
23
|
+
#
|
24
|
+
def each_data_path(path)
|
25
|
+
return enum_for(:each_data_path,path) unless block_given?
|
26
|
+
|
24
27
|
DataPaths.paths.each do |dir|
|
25
28
|
full_path = File.join(dir,path)
|
26
29
|
|
27
|
-
|
30
|
+
yield(full_path) if File.exists?(full_path)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -40,7 +43,7 @@ module DataPaths
|
|
40
43
|
# in any data directory.
|
41
44
|
#
|
42
45
|
def find_data_path(path)
|
43
|
-
|
46
|
+
each_data_path(path).first
|
44
47
|
end
|
45
48
|
|
46
49
|
#
|
@@ -55,11 +58,24 @@ module DataPaths
|
|
55
58
|
# in any data directory.
|
56
59
|
#
|
57
60
|
def find_data_file(path)
|
58
|
-
each_data_path(path)
|
59
|
-
|
60
|
-
end
|
61
|
+
each_data_path(path).find { |full_path| File.file?(full_path) }
|
62
|
+
end
|
61
63
|
|
62
|
-
|
64
|
+
#
|
65
|
+
# Loads the YAML file at the given path, within any data directory.
|
66
|
+
#
|
67
|
+
# @param [String] path
|
68
|
+
# The file path to search for.
|
69
|
+
#
|
70
|
+
# @return [Object]
|
71
|
+
# The contents of the YAML file.
|
72
|
+
#
|
73
|
+
# @since 0.3.0
|
74
|
+
#
|
75
|
+
def load_yaml_file(path)
|
76
|
+
if (file = find_data_file(path))
|
77
|
+
YAML.load_file(file)
|
78
|
+
end
|
63
79
|
end
|
64
80
|
|
65
81
|
#
|
@@ -75,11 +91,7 @@ module DataPaths
|
|
75
91
|
# found in any data directory.
|
76
92
|
#
|
77
93
|
def find_data_dir(path)
|
78
|
-
each_data_path(path)
|
79
|
-
return full_path if File.directory?(full_path)
|
80
|
-
end
|
81
|
-
|
82
|
-
return nil
|
94
|
+
each_data_path(path).find { |full_path| File.directory?(full_path) }
|
83
95
|
end
|
84
96
|
|
85
97
|
#
|
@@ -92,7 +104,7 @@ module DataPaths
|
|
92
104
|
# The occurrences of the given path within all data directories.
|
93
105
|
#
|
94
106
|
def all_data_paths(path)
|
95
|
-
|
107
|
+
each_data_path(path).to_a
|
96
108
|
end
|
97
109
|
|
98
110
|
#
|
@@ -108,16 +120,33 @@ module DataPaths
|
|
108
120
|
# @yieldparam [String] data_file
|
109
121
|
# The path of a file within a data directory.
|
110
122
|
#
|
111
|
-
# @return [
|
112
|
-
#
|
113
|
-
# directories.
|
123
|
+
# @return [Enumerator]
|
124
|
+
# If no block is given, an Enumerator object will be returned.
|
114
125
|
#
|
115
|
-
def each_data_file(path
|
126
|
+
def each_data_file(path)
|
127
|
+
return enum_for(:each_data_file,path) unless block_given?
|
128
|
+
|
116
129
|
each_data_path(path) do |full_path|
|
117
|
-
|
130
|
+
yield(full_path) if File.file?(full_path)
|
118
131
|
end
|
119
132
|
end
|
120
133
|
|
134
|
+
#
|
135
|
+
# Finds all occurrences of a given file path, within all data
|
136
|
+
# directories.
|
137
|
+
#
|
138
|
+
# @param [String] path
|
139
|
+
# The file path to search for.
|
140
|
+
#
|
141
|
+
# @return [Array]
|
142
|
+
# The loaded YAML files.
|
143
|
+
#
|
144
|
+
# @since 0.3.0
|
145
|
+
#
|
146
|
+
def load_yaml_files(path)
|
147
|
+
each_data_file.map { |file| YAML.load_file(file) }
|
148
|
+
end
|
149
|
+
|
121
150
|
#
|
122
151
|
#
|
123
152
|
# Finds all occurrences of a given file path, within all data
|
@@ -131,7 +160,7 @@ module DataPaths
|
|
131
160
|
# directories.
|
132
161
|
#
|
133
162
|
def all_data_files(path)
|
134
|
-
|
163
|
+
each_data_file(path).to_a
|
135
164
|
end
|
136
165
|
|
137
166
|
#
|
@@ -147,13 +176,14 @@ module DataPaths
|
|
147
176
|
# @yieldparam [String] data_dir
|
148
177
|
# The path of a directory within a data directory.
|
149
178
|
#
|
150
|
-
# @return [
|
151
|
-
#
|
152
|
-
# directories.
|
179
|
+
# @return [Enumerator]
|
180
|
+
# If no block is given, an Enumerator object will be returned.
|
153
181
|
#
|
154
|
-
def each_data_dir(path
|
182
|
+
def each_data_dir(path)
|
183
|
+
return enum_for(:each_data_dir,path) unless block_given?
|
184
|
+
|
155
185
|
each_data_path(path) do |full_path|
|
156
|
-
|
186
|
+
yield(full_path) if File.directory?(full_path)
|
157
187
|
end
|
158
188
|
end
|
159
189
|
|
@@ -169,7 +199,7 @@ module DataPaths
|
|
169
199
|
# directories.
|
170
200
|
#
|
171
201
|
def all_data_dirs(path)
|
172
|
-
|
202
|
+
each_data_dir(path).to_a
|
173
203
|
end
|
174
204
|
|
175
205
|
#
|
@@ -179,17 +209,34 @@ module DataPaths
|
|
179
209
|
# @param [String] pattern
|
180
210
|
# The path glob pattern to search with.
|
181
211
|
#
|
212
|
+
# @yield [path]
|
213
|
+
# If a block is given, it will be passed every matching path.
|
214
|
+
#
|
215
|
+
# @yieldparam [String] path
|
216
|
+
# The path of a matching file within a data directory.
|
217
|
+
#
|
182
218
|
# @return [Array<String>]
|
183
|
-
#
|
219
|
+
# If no block is given, the matching paths found within all data
|
220
|
+
# directories will be returned.
|
184
221
|
#
|
185
|
-
|
186
|
-
|
222
|
+
# @since 0.3.0
|
223
|
+
#
|
224
|
+
def glob_data_paths(pattern,&block)
|
225
|
+
return enum_for(:glob_data_paths,pattern).to_a unless block_given?
|
187
226
|
|
188
227
|
DataPaths.paths.each do |path|
|
189
|
-
|
228
|
+
Dir.glob(File.join(path,pattern),&block)
|
190
229
|
end
|
230
|
+
end
|
231
|
+
|
232
|
+
#
|
233
|
+
# @deprecated
|
234
|
+
# Will be removed in 1.0.0, please use {#glob_data_paths} instead.
|
235
|
+
#
|
236
|
+
def data_glob(pattern)
|
237
|
+
STDERR.puts "DEPRECATED: please use glob_data_paths instead."
|
191
238
|
|
192
|
-
|
239
|
+
glob_data_paths(pattern)
|
193
240
|
end
|
194
241
|
end
|
195
242
|
end
|
data/lib/data_paths/methods.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
1
|
module DataPaths
|
4
2
|
module Methods
|
5
3
|
#
|
6
4
|
# The directories registered within a specific module or class.
|
7
5
|
#
|
8
|
-
# @return [
|
6
|
+
# @return [Array<String>]
|
9
7
|
# The directories registered so far.
|
10
8
|
#
|
11
9
|
def data_paths
|
12
|
-
@data_paths ||=
|
10
|
+
@data_paths ||= []
|
13
11
|
end
|
14
12
|
|
15
13
|
#
|
@@ -27,44 +25,75 @@ module DataPaths
|
|
27
25
|
# @raise [RuntimeError]
|
28
26
|
# The specified path is not a directory.
|
29
27
|
#
|
30
|
-
|
31
|
-
|
28
|
+
# @since 0.3.0
|
29
|
+
#
|
30
|
+
def register_data_path(path)
|
31
|
+
DataPaths.register(path)
|
32
32
|
|
33
|
-
unless
|
34
|
-
|
35
|
-
|
33
|
+
data_paths << path unless data_paths.include?(path)
|
34
|
+
return path
|
35
|
+
end
|
36
36
|
|
37
|
-
|
37
|
+
#
|
38
|
+
# @deprecated
|
39
|
+
# Will be removed 1.0.0, please use {#register_data_path} instead.
|
40
|
+
#
|
41
|
+
def register_data_dir(path)
|
42
|
+
STDERR.puts "DEPRECATED: Please use register_data_path instead."
|
38
43
|
|
39
|
-
|
40
|
-
return path
|
44
|
+
register_data_path(path)
|
41
45
|
end
|
42
46
|
|
43
47
|
#
|
44
48
|
# Unregisters any matching data directories.
|
45
49
|
#
|
46
50
|
# @param [String] path
|
47
|
-
# The path to
|
51
|
+
# The path to unregister.
|
48
52
|
#
|
49
|
-
# @return [
|
53
|
+
# @return [String]
|
54
|
+
# The unregistered data path.
|
50
55
|
#
|
51
|
-
|
56
|
+
# @since 0.3.0
|
57
|
+
#
|
58
|
+
def unregister_data_path(path)
|
52
59
|
path = File.expand_path(path)
|
53
60
|
|
54
|
-
self.data_paths.
|
55
|
-
DataPaths.
|
56
|
-
|
61
|
+
self.data_paths.delete(path)
|
62
|
+
return DataPaths.unregister!(path)
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# @deprecated
|
67
|
+
# Will be removed 1.0.0, please use {#unregister_data_path} instead.
|
68
|
+
#
|
69
|
+
def unregister_data_dir!(path)
|
70
|
+
STDERR.puts "DEPRECATED: Please use unregister_data_path instead."
|
71
|
+
|
72
|
+
unregister_data_path(path)
|
57
73
|
end
|
58
74
|
|
59
75
|
#
|
60
76
|
# Unregisters all previously registered data directories.
|
61
77
|
#
|
62
78
|
# @return [true]
|
79
|
+
# Specifies all data paths were successfully unregistered.
|
63
80
|
#
|
64
|
-
|
65
|
-
|
66
|
-
|
81
|
+
# @since 0.3.0
|
82
|
+
#
|
83
|
+
def unregister_data_paths
|
84
|
+
data_paths.each { |path| DataPaths.unregister!(path) }
|
85
|
+
data_paths.clear
|
67
86
|
return true
|
68
87
|
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# @deprecated
|
91
|
+
# Will be removed 1.0.0, please use {#unregister_data_paths} instead.
|
92
|
+
#
|
93
|
+
def unregister_data_dirs!
|
94
|
+
STDERR.puts "DEPRECATED: Please use unregister_data_paths instead."
|
95
|
+
|
96
|
+
unregister_data_paths
|
97
|
+
end
|
69
98
|
end
|
70
99
|
end
|
data/lib/data_paths/version.rb
CHANGED
data/spec/data_paths_spec.rb
CHANGED
@@ -7,19 +7,13 @@ require 'methods_examples'
|
|
7
7
|
|
8
8
|
describe DataPaths do
|
9
9
|
describe "instance methods" do
|
10
|
-
include DataPaths
|
11
|
-
|
12
|
-
before(:all) do
|
13
|
-
@context = self
|
14
|
-
end
|
10
|
+
subject { Class.new { include DataPaths } }
|
15
11
|
|
16
12
|
it_should_behave_like "Methods"
|
17
13
|
end
|
18
14
|
|
19
15
|
describe "class methods" do
|
20
|
-
|
21
|
-
@context = DataClass
|
22
|
-
end
|
16
|
+
subject { DataClass }
|
23
17
|
|
24
18
|
it_should_behave_like "Methods"
|
25
19
|
end
|
data/spec/finders_spec.rb
CHANGED
@@ -1,37 +1,40 @@
|
|
1
|
-
require 'data_paths/finders'
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
require 'helpers/data'
|
5
3
|
|
4
|
+
require 'data_paths/finders'
|
5
|
+
|
6
6
|
describe DataPaths::Finders do
|
7
|
-
|
8
|
-
|
7
|
+
subject do
|
8
|
+
Class.new {
|
9
|
+
include DataPaths
|
10
|
+
include DataPaths::Finders
|
11
|
+
}.new
|
9
12
|
end
|
10
13
|
|
11
14
|
it "should find a file" do
|
12
|
-
|
15
|
+
subject.find_data_file('one.txt').should == File.join(Helpers::DATA_DIRS[0],'one.txt')
|
13
16
|
end
|
14
17
|
|
15
18
|
it "should find a directory" do
|
16
|
-
|
19
|
+
subject.find_data_dir('dir').should == File.join(Helpers::DATA_DIRS[0],'dir')
|
17
20
|
end
|
18
21
|
|
19
22
|
it "should find all matching files" do
|
20
|
-
|
23
|
+
subject.all_data_files('dir/two.txt').should == [
|
21
24
|
File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
|
22
25
|
File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
|
23
26
|
]
|
24
27
|
end
|
25
28
|
|
26
29
|
it "should find all matching directories" do
|
27
|
-
|
30
|
+
subject.all_data_dirs('dir').should == [
|
28
31
|
File.join(Helpers::DATA_DIRS[0],'dir'),
|
29
32
|
File.join(Helpers::DATA_DIRS[1],'dir')
|
30
33
|
]
|
31
34
|
end
|
32
35
|
|
33
36
|
it "should find all paths matching a pattern" do
|
34
|
-
|
37
|
+
subject.glob_data_paths('*/*.txt').should == [
|
35
38
|
File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
|
36
39
|
File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
|
37
40
|
]
|
data/spec/helpers/data.rb
CHANGED
data/spec/methods_examples.rb
CHANGED
@@ -6,25 +6,25 @@ require 'helpers/data'
|
|
6
6
|
shared_examples_for "Methods" do
|
7
7
|
before(:all) do
|
8
8
|
Helpers::DATA_DIRS.each do |dir|
|
9
|
-
|
9
|
+
subject.register_data_path dir
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should list data directories" do
|
14
14
|
Helpers::DATA_DIRS.each do |dir|
|
15
|
-
|
15
|
+
subject.data_paths.should include(dir)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should prevent the addition of non-existant directories" do
|
20
20
|
lambda {
|
21
|
-
|
21
|
+
subject.register_data_path 'lol'
|
22
22
|
}.should raise_error(RuntimeError)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should prevent the addition of non-directories" do
|
26
26
|
lambda {
|
27
|
-
|
27
|
+
subject.register_data_path __FILE__
|
28
28
|
}.should raise_error(RuntimeError)
|
29
29
|
end
|
30
30
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_paths
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 1
|
9
|
-
version: 0.2.1
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.3.0.rc1
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Postmodern
|
@@ -14,56 +10,60 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
13
|
+
date: 2011-05-14 00:00:00 Z
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
16
|
+
name: ore-tasks
|
22
17
|
prerelease: false
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
24
20
|
requirements:
|
25
|
-
- -
|
21
|
+
- - ~>
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 1
|
29
|
-
- 3
|
30
|
-
- 0
|
31
|
-
version: 1.3.0
|
23
|
+
version: "0.4"
|
32
24
|
type: :development
|
33
25
|
version_requirements: *id001
|
34
26
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
27
|
+
name: rspec
|
36
28
|
prerelease: false
|
37
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
38
31
|
requirements:
|
39
|
-
- -
|
32
|
+
- - ~>
|
40
33
|
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
- 0
|
43
|
-
- 5
|
44
|
-
- 3
|
45
|
-
version: 0.5.3
|
34
|
+
version: "2.4"
|
46
35
|
type: :development
|
47
36
|
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.6.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
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:
|
49
|
+
email:
|
50
|
+
- postmodern.mod3@gmail.com
|
50
51
|
executables: []
|
51
52
|
|
52
53
|
extensions: []
|
53
54
|
|
54
55
|
extra_rdoc_files:
|
55
|
-
- ChangeLog.md
|
56
|
-
- LICENSE.txt
|
57
56
|
- README.md
|
58
57
|
files:
|
59
|
-
- .
|
60
|
-
- .
|
58
|
+
- .gemtest
|
59
|
+
- .rspec
|
61
60
|
- .yardopts
|
62
61
|
- ChangeLog.md
|
63
62
|
- LICENSE.txt
|
64
63
|
- README.md
|
65
64
|
- Rakefile
|
66
65
|
- data_paths.gemspec
|
66
|
+
- gemspec.yml
|
67
67
|
- lib/data_paths.rb
|
68
68
|
- lib/data_paths/data_paths.rb
|
69
69
|
- lib/data_paths/finders.rb
|
@@ -78,40 +78,33 @@ files:
|
|
78
78
|
- spec/helpers/data2/dir/two.txt
|
79
79
|
- spec/methods_examples.rb
|
80
80
|
- spec/spec_helper.rb
|
81
|
-
has_rdoc: yard
|
82
81
|
homepage: http://github.com/postmodern/data_paths
|
83
|
-
licenses:
|
84
|
-
|
82
|
+
licenses:
|
83
|
+
- MIT
|
85
84
|
post_install_message:
|
86
|
-
rdoc_options:
|
87
|
-
|
85
|
+
rdoc_options: []
|
86
|
+
|
88
87
|
require_paths:
|
89
88
|
- lib
|
90
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
91
|
requirements:
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
segments:
|
95
|
-
- 0
|
96
94
|
version: "0"
|
97
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
98
97
|
requirements:
|
99
98
|
- - ">="
|
100
99
|
- !ruby/object:Gem::Version
|
101
|
-
segments:
|
102
|
-
- 0
|
103
100
|
version: "0"
|
104
101
|
requirements: []
|
105
102
|
|
106
|
-
rubyforge_project:
|
107
|
-
rubygems_version: 1.
|
103
|
+
rubyforge_project: data_paths
|
104
|
+
rubygems_version: 1.8.1
|
108
105
|
signing_key:
|
109
106
|
specification_version: 3
|
110
|
-
summary: DataPaths is a library to manage
|
107
|
+
summary: DataPaths is a library to manage multiple data/ directories.
|
111
108
|
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
109
|
- spec/data_paths_spec.rb
|
110
|
+
- spec/finders_spec.rb
|
data/.gitignore
DELETED
data/.specopts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour --format specdoc
|