require-dsl 0.2.1
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +168 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/require-dsl.rb +198 -0
- data/spec/.rspec +1 -0
- data/spec/required/except_also_me.rb +0 -0
- data/spec/required/except_me.rb +0 -0
- data/spec/required/not_me.erb.rb +0 -0
- data/spec/required/not_this_folder/sub_not_me.rb +0 -0
- data/spec/required/only_me.rb +0 -0
- data/spec/required/required_spec.rb +113 -0
- data/spec/required/this_folder/subsub/a_sub_sub_file.rb +0 -0
- data/spec/required/this_folder/yes_me.rb +0 -0
- data/spec/spec_helper.rb +11 -0
- metadata +105 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# Required
|
2
|
+
|
3
|
+
Handle load and require ruby files using a nice DSL.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
<code>gem install require-dsl</code>
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
<code>require 'require-dsl'</code>
|
12
|
+
|
13
|
+
## Using the DSL
|
14
|
+
|
15
|
+
Imagine we are using the DSL inside a file basic.rb in <code>lib/project/report</code>
|
16
|
+
|
17
|
+
Passing 'spec' and the current file, lets Required determine that it should create require statements relative to 'spec' as the root folder.
|
18
|
+
The method 'ruby_files' is evaluated in the context of the file it is used in, i.e File.dirname(__FILE___) which could alternatively be passed as the second argument.
|
19
|
+
|
20
|
+
### Recursive option
|
21
|
+
|
22
|
+
By default the files are evaluated non-recursively, that is within the current folder and not any subfolders. You can explicitly set it with the <code>:recursive => :none</code> option
|
23
|
+
|
24
|
+
<pre>
|
25
|
+
# lib/project/report/basic.rb
|
26
|
+
|
27
|
+
ruby_files('spec', __FILE__) # OR ruby_files('spec', __FILE__, :recursive => :none)
|
28
|
+
==> ['lib/project/report/basic.rb']
|
29
|
+
</pre>
|
30
|
+
|
31
|
+
To evaluate all files within the current folder and recursively one level below, use the <code>:recursive => :single</code> option.
|
32
|
+
|
33
|
+
<pre>
|
34
|
+
# lib/project/report/basic.rb
|
35
|
+
|
36
|
+
ruby_files('spec', __FILE__, :recursive => :single)
|
37
|
+
==> ['lib/project/report/basic.rb', 'lib/project/report/subfolder/in_the_sub.rb']
|
38
|
+
</pre>
|
39
|
+
|
40
|
+
To evaluate all files within the current folder and recursively traversing the complete hierarchy of subfolders, use the <code>:recursive => :full</code> option.
|
41
|
+
|
42
|
+
<pre>
|
43
|
+
# lib/project/report/basic.rb
|
44
|
+
|
45
|
+
ruby_files('spec', __FILE__, :recursive => :full)
|
46
|
+
==> ['lib/project/report/basic.rb', 'lib/project/report/subfolder/in_the_sub.rb',
|
47
|
+
'lib/project/report/subfolder/sub_sub/in_the_sub_of_the_sub.rb']
|
48
|
+
</pre>
|
49
|
+
|
50
|
+
### Except conditions
|
51
|
+
|
52
|
+
You can chain except_file(s) and except_folder(s) conditions on the filelist returned by ruby_files to filter out specific files and folders.
|
53
|
+
|
54
|
+
#### Condition: except_file(s)
|
55
|
+
|
56
|
+
<pre>
|
57
|
+
# Context: An extra file 'except_me.rb' has been added to the project/report folder:
|
58
|
+
|
59
|
+
ruby_files('lib', __FILE__).except_file('except_me')
|
60
|
+
==> 'project/report/basic.rb'
|
61
|
+
|
62
|
+
# Context: An extra file 'except_also_me.rb' has been added to the folder:
|
63
|
+
|
64
|
+
ruby_files('lib', __FILE__).except_files('except_me', 'except_also_me')
|
65
|
+
==> 'project/report/basic.rb'
|
66
|
+
|
67
|
+
ruby_files('lib', __FILE__).except_file('except_me').except_files('except_also_me')
|
68
|
+
==> 'project/report/basic.rb'
|
69
|
+
</pre>
|
70
|
+
|
71
|
+
#### Condition: except_folder(s)
|
72
|
+
|
73
|
+
<pre>
|
74
|
+
# Context: Extra folders 'not_me_folder' and 'me_folder' has been added to the project/report folder:
|
75
|
+
|
76
|
+
ruby_files('lib', __FILE__).except_folder('not_me_folder')
|
77
|
+
==> 'project/report/basic.rb', 'project/report/me_folder/yes_me.rb'
|
78
|
+
|
79
|
+
ruby_files('lib', __FILE__).except_folders('not_me_folder', 'me_folder')
|
80
|
+
==> 'project/report/basic.rb'
|
81
|
+
|
82
|
+
ruby_files('lib', __FILE__).except_folder('not_me_folder').except_folders('me_folder')
|
83
|
+
==> 'project/report/basic.rb'
|
84
|
+
</pre>
|
85
|
+
|
86
|
+
### Only conditions
|
87
|
+
|
88
|
+
You can chain only_file(s) and only_folder(s) conditions on the filelist returned by ruby_files to filter out specific files and folders.
|
89
|
+
|
90
|
+
Note: It rarely makes sense to chain multiple only conditions.
|
91
|
+
|
92
|
+
#### Condition: only_file(s)
|
93
|
+
|
94
|
+
<pre>
|
95
|
+
# Context: An extra file 'only_me.rb' has been added to the project/report folder:
|
96
|
+
|
97
|
+
ruby_files('lib', __FILE__).only_file('only_me')
|
98
|
+
==> 'project/report/only_me.rb'
|
99
|
+
|
100
|
+
# Context: An extra file 'also_only_me.rb' has been added to the folder:
|
101
|
+
|
102
|
+
ruby_files('lib', __FILE__).only_files('only_me', 'also_only_me')
|
103
|
+
==> 'project/report/only_me.rb', 'project/report/also_only_me.rb'
|
104
|
+
</pre>
|
105
|
+
|
106
|
+
#### Condition: only_folder(s)
|
107
|
+
|
108
|
+
<pre>
|
109
|
+
# Context: Extra folders 'only_me_folder' and 'me_folder' has been added to the project/report folder:
|
110
|
+
|
111
|
+
ruby_files('lib', __FILE__).only_folder('only_me_folder')
|
112
|
+
==> 'project/report/basic.rb', 'project/report/only_me_folder/yes_me.rb'
|
113
|
+
|
114
|
+
ruby_files('lib', __FILE__).only_folders('only_me_folder', 'me_folder')
|
115
|
+
==> 'project/report/basic.rb', 'project/report/only_me_folder/yes_me.rb', 'project/report/me_folder/me.rb'
|
116
|
+
</pre>
|
117
|
+
|
118
|
+
|
119
|
+
## strip_file_ext
|
120
|
+
|
121
|
+
Chaining a call to strip_file_ext, ensures that the file list is stripped of the .rb ending and thus usable for fx require statements.
|
122
|
+
|
123
|
+
<pre>
|
124
|
+
# lib/project/report/basic.rb
|
125
|
+
|
126
|
+
ruby_files('lib', __FILE__).strip_file_ext
|
127
|
+
==> 'project/report/basic'
|
128
|
+
</pre>
|
129
|
+
|
130
|
+
The method *strip_file_ext* can take an argument to indicate a built-in action to perform on this file liust, fx load the files into ruby kernel (:load or :require), display them for debugging (:display)
|
131
|
+
|
132
|
+
<pre>
|
133
|
+
# lib/project/report/basic.rb
|
134
|
+
|
135
|
+
ruby_files('lib', __FILE__).except('except_me', 'except_also_me').strip_file_ext :display => 'require'
|
136
|
+
==> PRINTS "require 'project/report/basic'\n" to STDOUT
|
137
|
+
|
138
|
+
ruby_files('lib', __FILE__).except('except_me', 'except_also_me').strip_file_ext :require
|
139
|
+
==> 'project/report/basic' loaded into Ruby and executed if not previously loaded (using Ruby Kernel 'require' statement)
|
140
|
+
|
141
|
+
ruby_files('lib', __FILE__).except('except_me', 'except_also_me').strip_file_ext :load
|
142
|
+
==> 'project/report/basic' loaded into Ruby and executed (using Ruby Kernel 'load' statement)
|
143
|
+
</pre>
|
144
|
+
|
145
|
+
## output to StringIO
|
146
|
+
|
147
|
+
<pre>
|
148
|
+
out = StringIO.new
|
149
|
+
ruby_files('lib', __FILE__, :stdout => out).strip_file_ext :display => :load
|
150
|
+
out.rewind
|
151
|
+
puts out.read
|
152
|
+
==> PRINTS "load 'project/report/basic'\n" to STDOUT
|
153
|
+
|
154
|
+
</pre>
|
155
|
+
|
156
|
+
## Note on Patches/Pull Requests
|
157
|
+
|
158
|
+
* Fork the project.
|
159
|
+
* Make your feature addition or bug fix.
|
160
|
+
* Add tests for it. This is important so I don't break it in a
|
161
|
+
future version unintentionally.
|
162
|
+
* Commit, do not mess with rakefile, version, or history.
|
163
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
164
|
+
* Send me a pull request. Bonus points for topic branches.
|
165
|
+
|
166
|
+
## Copyright
|
167
|
+
|
168
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "require-dsl"
|
8
|
+
gem.summary = %Q{DSL to facilitate require/load of ruby files and folders}
|
9
|
+
gem.description = %Q{DSL to facilitate require/load of ruby files and folders}
|
10
|
+
gem.email = "kmandrup@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/kristianmandrup/required"
|
12
|
+
gem.authors = ["Kristian Mandrup"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.14"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
# require 'spec/rake/spectask'
|
22
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
# spec.libs << 'lib' << 'spec'
|
24
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
# spec.libs << 'lib' << 'spec'
|
29
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
# spec.rcov = true
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# task :spec => :check_dependencies
|
34
|
+
#
|
35
|
+
# task :default => :spec
|
36
|
+
#
|
37
|
+
# require 'rake/rdoctask'
|
38
|
+
# Rake::RDocTask.new do |rdoc|
|
39
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
#
|
41
|
+
# rdoc.rdoc_dir = 'rdoc'
|
42
|
+
# rdoc.title = "required #{version}"
|
43
|
+
# rdoc.rdoc_files.include('README*')
|
44
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/lib/require-dsl.rb
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
def ruby_files base_path, path, options = {}, &block
|
4
|
+
required = Required.new(base_path, path)
|
5
|
+
stdout = options[:stdout] if options[:stdout]
|
6
|
+
required.stdout = stdout
|
7
|
+
files = []
|
8
|
+
dir = File.dirname path
|
9
|
+
FileUtils.cd dir do |dir|
|
10
|
+
glob = Required.glob(options)
|
11
|
+
files = FileList.new(glob)
|
12
|
+
Required.extend_files(files, required)
|
13
|
+
files.select_ruby_files!
|
14
|
+
files.prefix_with_path! required.location
|
15
|
+
end
|
16
|
+
if block
|
17
|
+
block.arity < 1 ? files.instance_eval(&block) : block.call(files)
|
18
|
+
else
|
19
|
+
files
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Required
|
24
|
+
attr_accessor :location, :stdout
|
25
|
+
|
26
|
+
def initialize base_path, path
|
27
|
+
rel_path = relative_path(base_path, path)
|
28
|
+
@location = File.dirname(rel_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.glob options
|
32
|
+
case options[:recursive]
|
33
|
+
when :full
|
34
|
+
'**/*.rb'
|
35
|
+
when :single
|
36
|
+
['*/*.rb', '*.rb']
|
37
|
+
else
|
38
|
+
'*.rb'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.extend_files files, required
|
43
|
+
files.extend(FileListExtension).required = required
|
44
|
+
files.map! do |f|
|
45
|
+
f.extend(FileString)
|
46
|
+
f.required = required
|
47
|
+
f
|
48
|
+
end
|
49
|
+
files
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def relative_path base_path, path
|
55
|
+
last_part_path = path.gsub /(\S*?)#{Regexp.escape(base_path)}\/(.*?)/, '\2'
|
56
|
+
File.join(base_path, last_part_path)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
module FileListExtension
|
62
|
+
|
63
|
+
attr_accessor :required
|
64
|
+
|
65
|
+
def prefix_with_path! location
|
66
|
+
self.map! do |f|
|
67
|
+
f = File.join(location, f).extend(FileString)
|
68
|
+
f.required = required
|
69
|
+
f
|
70
|
+
end
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
def strip_file_ext mode = nil
|
75
|
+
self.map!{|f| f.remove_rb }
|
76
|
+
if mode
|
77
|
+
self.action mode
|
78
|
+
else
|
79
|
+
self
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def select_ruby_files!
|
84
|
+
self.select! {|f| (f =~ /[^\.]*.rb$/) == 0 }
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def except_folders *reject_folders
|
89
|
+
self.reject! do |file|
|
90
|
+
file.matches_any_folder reject_folders
|
91
|
+
end
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def except_files *reject_files
|
97
|
+
self.reject! do |file|
|
98
|
+
file.matches_any reject_files
|
99
|
+
end
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
def only_folders *only_folders
|
104
|
+
self.select! do |file|
|
105
|
+
!file.inside_a_folder? || file.matches_any_folder(only_folders)
|
106
|
+
end
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
110
|
+
def only_files *only_files
|
111
|
+
self.select! do |file|
|
112
|
+
file.matches_any only_files
|
113
|
+
end
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
def action mode = :require
|
120
|
+
self.each{|f| f.handle_file mode}
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
module FileString
|
127
|
+
|
128
|
+
attr_accessor :required
|
129
|
+
|
130
|
+
def handle_file mode = nil
|
131
|
+
stdout = required.stdout
|
132
|
+
case mode
|
133
|
+
when Hash
|
134
|
+
case stdout
|
135
|
+
when StringIO
|
136
|
+
stdout.write display_text(mode)
|
137
|
+
else
|
138
|
+
puts "#{mode[:display]} '#{self}'" if mode[:display]
|
139
|
+
puts self if !mode[:display]
|
140
|
+
end
|
141
|
+
|
142
|
+
when :display
|
143
|
+
stdout.puts self
|
144
|
+
when :require
|
145
|
+
require self
|
146
|
+
when :require
|
147
|
+
load self
|
148
|
+
else
|
149
|
+
self
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def display_text mode
|
154
|
+
mode[:display] ? "#{mode[:display]} '#{self}'\n" : "#{self}\n"
|
155
|
+
end
|
156
|
+
|
157
|
+
def remove_rb
|
158
|
+
self.sub!('.rb', '')
|
159
|
+
end
|
160
|
+
|
161
|
+
def matches_any match_files
|
162
|
+
match_files.any? {|match_file| match? match_file }
|
163
|
+
end
|
164
|
+
|
165
|
+
def matches_any_folder match_folders
|
166
|
+
match_folders.any? {|match_folder| match_folder? match_folder }
|
167
|
+
end
|
168
|
+
|
169
|
+
def inside_a_folder?
|
170
|
+
return true if (self =~ /#{Regexp.escape(required.location)}\/(.*?)\//) != nil
|
171
|
+
end
|
172
|
+
|
173
|
+
protected
|
174
|
+
|
175
|
+
def match? match_file
|
176
|
+
case match_file
|
177
|
+
when String
|
178
|
+
(self =~ /#{Regexp.escape(match_file)}.rb$/) != nil
|
179
|
+
when Regexp
|
180
|
+
(self =~ /#{match_file.source}.rb$/) != nil
|
181
|
+
else
|
182
|
+
raise ArgumentError, "File matcher must be either a String or RegExp"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def match_folder? match_folder
|
187
|
+
case match_folder
|
188
|
+
when String
|
189
|
+
(self =~ /#{Regexp.escape(required.location)}\/#{Regexp.escape(match_folder)}\//) != nil
|
190
|
+
when Regexp
|
191
|
+
(self =~ /#{Regexp.escape(required.location)}\/#{match_folder.source}\//) != nil
|
192
|
+
else
|
193
|
+
raise ArgumentError, "File matcher must be either a String or RegExp"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
end
|
data/spec/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
class String
|
4
|
+
def remove_rb
|
5
|
+
self.sub!('.rb', '')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def path *args
|
10
|
+
File.join args
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_folder
|
14
|
+
File.dirname(__FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Required" do
|
18
|
+
let (:folder) { current_folder }
|
19
|
+
let (:dir) { 'spec/required' }
|
20
|
+
|
21
|
+
context "current folder: #{current_folder}" do
|
22
|
+
describe '#' do
|
23
|
+
it "should list all 'pure' ruby files, , none recursive" do
|
24
|
+
res = ruby_files('spec', __FILE__)
|
25
|
+
res2 = ruby_files('spec', __FILE__, :recursive => :none)
|
26
|
+
res.should == res2
|
27
|
+
res.should include(path dir, File.basename(__FILE__) )
|
28
|
+
res.should_not include(path dir, 'not_me.erb.rb' )
|
29
|
+
res.should_not include(path dir, 'not_this_folder', 'sub_not_me.rb' )
|
30
|
+
res.should_not include(path dir, 'this_folder', 'yes_me.rb' )
|
31
|
+
res.should_not include(path dir, 'this_folder', 'subsub', 'a_sub_sub_file.rb' )
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should list all 'pure' ruby files, full recursive" do
|
35
|
+
res = ruby_files('spec', __FILE__, :recursive => :full)
|
36
|
+
res.should include(path dir, 'this_folder', 'subsub', 'a_sub_sub_file.rb' )
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should list all 'pure' ruby files, single recursive" do
|
40
|
+
res = ruby_files('spec', __FILE__, :recursive => :single)
|
41
|
+
res.should include(path dir, File.basename(__FILE__) )
|
42
|
+
res.should_not include(path dir, 'this_folder', 'subsub', 'a_sub_sub_file.rb' )
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should list all 'pure' ruby files except one file" do
|
46
|
+
res = ruby_files('spec', __FILE__).except_files('except_me')
|
47
|
+
res.should include(path dir, File.basename(__FILE__))
|
48
|
+
res.should_not include(path dir, 'not_me.erb.rb')
|
49
|
+
res.should_not include(path dir, 'except_me.rb')
|
50
|
+
res.should include(path dir, 'except_also_me.rb') # not in except list
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should list all 'pure' ruby files except one file using block DSL" do
|
54
|
+
res = ruby_files('spec', __FILE__) do
|
55
|
+
except_files('except_me')
|
56
|
+
end
|
57
|
+
res.should include(path dir, File.basename(__FILE__))
|
58
|
+
res.should_not include(path dir, 'not_me.erb.rb')
|
59
|
+
res.should_not include(path dir, 'except_me.rb')
|
60
|
+
res.should include(path dir, 'except_also_me.rb') # not in except list
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
it "should list all 'pure' ruby files except two file" do
|
65
|
+
res = ruby_files('spec', __FILE__).except_files('except_me', 'except_also_me')
|
66
|
+
res2 = ruby_files('spec', __FILE__).except_files('except_me').except_files('except_also_me')
|
67
|
+
res2.should == res
|
68
|
+
res.should include(path dir, File.basename(__FILE__))
|
69
|
+
res.should_not include(path dir, 'not_me.erb.rb')
|
70
|
+
res.should_not include(path dir, 'except_me.rb')
|
71
|
+
res.should_not include(path dir, 'except_also_me.rb')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should list required files" do
|
75
|
+
res = ruby_files('spec', __FILE__).except_files('except_me').strip_file_ext
|
76
|
+
res.should include(path dir, File.basename(__FILE__).remove_rb)
|
77
|
+
res.should_not include(path dir, 'not_me.erb')
|
78
|
+
res.should_not include(path dir, 'except_me')
|
79
|
+
res.should include(path dir, 'except_also_me')
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should list only required files" do
|
83
|
+
out = StringIO.new
|
84
|
+
res = ruby_files('spec', __FILE__, :stdout => out).only_files(/.*only.*/).strip_file_ext :display => :require
|
85
|
+
out.rewind
|
86
|
+
out.read.should match /require '(.*?)'/
|
87
|
+
res.should_not include(path dir, File.basename(__FILE__).remove_rb)
|
88
|
+
res.should include(path dir, 'only_me')
|
89
|
+
res.should_not include(path dir, 'except_me')
|
90
|
+
res.should_not include(path dir, 'except_also_me')
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should list all 'pure' ruby files except one subfolder using block DSL" do
|
94
|
+
res = ruby_files('spec', __FILE__, :recursive => :full) do
|
95
|
+
except_folders('not_this_folder')
|
96
|
+
end.strip_file_ext
|
97
|
+
res.should include(path dir, File.basename(__FILE__).remove_rb)
|
98
|
+
res.should include(path dir, 'this_folder', 'yes_me')
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should list all 'pure' ruby files except one subfolder using block DSL" do
|
102
|
+
res = ruby_files('spec', __FILE__, :recursive => :full) do
|
103
|
+
only_folders('this_folder')
|
104
|
+
end.strip_file_ext
|
105
|
+
res.should include(path dir, File.basename(__FILE__).remove_rb)
|
106
|
+
res.should include(path dir, 'this_folder', 'yes_me')
|
107
|
+
res.should_not include(path dir, 'not_this_folder', 'sub_not_me')
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: require-dsl
|
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
|
+
- Kristian Mandrup
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-29 00:00:00 +02: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
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta
|
33
|
+
- 14
|
34
|
+
version: 2.0.0.beta.14
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: DSL to facilitate require/load of ruby files and folders
|
38
|
+
email: kmandrup@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.markdown
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.markdown
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- lib/require-dsl.rb
|
54
|
+
- spec/.rspec
|
55
|
+
- spec/required/except_also_me.rb
|
56
|
+
- spec/required/except_me.rb
|
57
|
+
- spec/required/not_me.erb.rb
|
58
|
+
- spec/required/not_this_folder/sub_not_me.rb
|
59
|
+
- spec/required/only_me.rb
|
60
|
+
- spec/required/required_spec.rb
|
61
|
+
- spec/required/this_folder/subsub/a_sub_sub_file.rb
|
62
|
+
- spec/required/this_folder/yes_me.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/kristianmandrup/required
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.7
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: DSL to facilitate require/load of ruby files and folders
|
96
|
+
test_files:
|
97
|
+
- spec/required/except_also_me.rb
|
98
|
+
- spec/required/except_me.rb
|
99
|
+
- spec/required/not_me.erb.rb
|
100
|
+
- spec/required/not_this_folder/sub_not_me.rb
|
101
|
+
- spec/required/only_me.rb
|
102
|
+
- spec/required/required_spec.rb
|
103
|
+
- spec/required/this_folder/subsub/a_sub_sub_file.rb
|
104
|
+
- spec/required/this_folder/yes_me.rb
|
105
|
+
- spec/spec_helper.rb
|