require-me 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/folder/folder.rb +50 -8
- data/lib/folder/magic.rb +42 -1
- data/spec/dsl/recursive/slammer.rb +1 -0
- data/spec/dsl/require-dsl_spec.rb +3 -3
- data/test/test_require_folder.rb +1 -1
- metadata +4 -2
data/lib/folder/folder.rb
CHANGED
@@ -61,12 +61,28 @@ module Folder
|
|
61
61
|
require relative_path(req_file, source, 'test')
|
62
62
|
end
|
63
63
|
|
64
|
+
def self.require_all_recursive(*folders)
|
65
|
+
if folders.empty?
|
66
|
+
magics = Magic.new.all_recursive
|
67
|
+
return magics.dup.extend(MagicList).do_require
|
68
|
+
end
|
69
|
+
folders.each do |folder|
|
70
|
+
enter folder do |f|
|
71
|
+
fs = f.all_recursive
|
72
|
+
fs.dup.extend(MagicList).do_require
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
64
76
|
|
65
77
|
def self.require_all(*folders)
|
66
|
-
|
78
|
+
if folders.empty?
|
79
|
+
magics = Magic.new.all
|
80
|
+
return magics.dup.extend(MagicList).do_require
|
81
|
+
end
|
67
82
|
folders.each do |folder|
|
68
83
|
enter folder do |f|
|
69
|
-
f.all
|
84
|
+
fs = f.all
|
85
|
+
fs.dup.extend(MagicList).do_require
|
70
86
|
end
|
71
87
|
end
|
72
88
|
end
|
@@ -75,23 +91,49 @@ module Folder
|
|
75
91
|
require_all File.dirname(file_name)
|
76
92
|
end
|
77
93
|
|
78
|
-
def self.
|
79
|
-
|
94
|
+
def self.require_all_recursive_here(file_name)
|
95
|
+
require_all_recursive File.dirname(file_name)
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.show_require_all_recursive(*folders)
|
99
|
+
if folders.empty?
|
100
|
+
magics = Magic.new.all_recursive
|
101
|
+
return magics.dup.extend(MagicList).show_require
|
102
|
+
end
|
80
103
|
folders.each do |folder|
|
81
|
-
enter folder do |f|
|
82
|
-
f.
|
104
|
+
enter folder do |f|
|
105
|
+
fs = f.all_recursive
|
106
|
+
fs.dup.extend(MagicList).show_require
|
83
107
|
end
|
84
108
|
end
|
85
109
|
end
|
86
110
|
|
111
|
+
def self.show_require_all(*folders)
|
112
|
+
if folders.empty?
|
113
|
+
magics = Magic.new.all
|
114
|
+
return magics.dup.extend(MagicList).show_require
|
115
|
+
end
|
116
|
+
folders.each do |folder|
|
117
|
+
enter folder do |f|
|
118
|
+
fs = f.all
|
119
|
+
fs.dup.extend(MagicList).show_require
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
87
123
|
|
88
124
|
def self.here(file)
|
89
125
|
FileUtils.cd File.dirname(file)
|
90
126
|
self
|
91
127
|
end
|
92
128
|
|
93
|
-
def self.
|
94
|
-
|
129
|
+
def self.require_me_recursive(*files)
|
130
|
+
magics = Magic.new.all_recursive(files)
|
131
|
+
return magics.dup.extend(MagicList).do_require
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.require_me(*files)
|
135
|
+
magics = Magic.new.all(files)
|
136
|
+
return magics.dup.extend(MagicList).do_require
|
95
137
|
end
|
96
138
|
|
97
139
|
|
data/lib/folder/magic.rb
CHANGED
@@ -45,12 +45,19 @@ module Folder
|
|
45
45
|
end
|
46
46
|
|
47
47
|
|
48
|
-
def
|
48
|
+
def all_recursive(*globs)
|
49
49
|
globs = '**/*.rb' if globs.empty?
|
50
50
|
list = FileList.new(globs)
|
51
51
|
magic_list(list)
|
52
52
|
end
|
53
53
|
|
54
|
+
def all(*globs)
|
55
|
+
globs = '*.rb' if globs.empty?
|
56
|
+
list = FileList.new(globs)
|
57
|
+
magic_list(list)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
54
61
|
def require_all(*folders)
|
55
62
|
return require_all_here(folders[0]) if folders.size == 1 && folders[0] =~ '.rb'
|
56
63
|
relative = {:relative_to => relative_path || ''}
|
@@ -74,15 +81,49 @@ module Folder
|
|
74
81
|
end
|
75
82
|
end
|
76
83
|
|
84
|
+
def require_all_recursive(*folders)
|
85
|
+
return require_all_here(folders[0]) if folders.size == 1 && folders[0] =~ '.rb'
|
86
|
+
relative = {:relative_to => relative_path || ''}
|
87
|
+
relative = folders.pop if folders && !folders.empty? && folders.last.kind_of?(Hash)
|
88
|
+
|
89
|
+
# puts "relative_to: #{relative[:relative_to]}"
|
90
|
+
|
91
|
+
if folders.empty?
|
92
|
+
files = all_recursive.dup.extend(MagicList)
|
93
|
+
files.rel_path = relative[:relative_to]
|
94
|
+
return files.do_require
|
95
|
+
end
|
96
|
+
|
97
|
+
# puts "iterate"
|
98
|
+
folders.each do |folder|
|
99
|
+
enter folder do |f|
|
100
|
+
file = f.all_recursive.dup.extend(MagicList)
|
101
|
+
require_relative_to = relative ? relative_to(folder, relative) : folder
|
102
|
+
file.do_require(require_relative_to)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
77
108
|
def require_me(*files)
|
78
109
|
file = all(files).dup.extend(MagicList)
|
79
110
|
file.do_require(relative_path)
|
80
111
|
end
|
81
112
|
|
113
|
+
def require_me_recursive(*files)
|
114
|
+
file = all_recursive(files).dup.extend(MagicList)
|
115
|
+
file.do_require(relative_path)
|
116
|
+
end
|
117
|
+
|
82
118
|
def require_all_here(file_name)
|
83
119
|
require_all File.dirname(file_name)
|
84
120
|
end
|
85
121
|
|
122
|
+
def require_all_recursive_here(file_name)
|
123
|
+
require_all_recursive File.dirname(file_name)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
86
127
|
protected
|
87
128
|
|
88
129
|
def relative_to(folder, relative)
|
@@ -0,0 +1 @@
|
|
1
|
+
puts "Slammer included"
|
@@ -15,7 +15,7 @@ describe "RequireMagic" do
|
|
15
15
|
it "just works " do
|
16
16
|
Folder.enter '../../fixtures' do |folder| # oops!
|
17
17
|
folder.enter 'game' do |f|
|
18
|
-
list = f.
|
18
|
+
list = f.all_recursive #('**/*.rb')
|
19
19
|
l1 = list.matching( 'sound', 'network').except(/sound/)
|
20
20
|
|
21
21
|
# require fx 'game/network/network.rb'
|
@@ -81,8 +81,8 @@ describe "RequireMagic" do
|
|
81
81
|
folder.enter 'game' do |f|
|
82
82
|
f.relative_to_me # set implicit by default
|
83
83
|
|
84
|
-
f.
|
85
|
-
list = f.
|
84
|
+
f.require_all_recursive
|
85
|
+
list = f.all_recursive # ('**/*.rb')
|
86
86
|
l1 = list.matching( 'sound', 'network').except(/sound/).show_require(:relative).inspect
|
87
87
|
l1.should include("network/network.rb")
|
88
88
|
|
data/test/test_require_folder.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 5
|
9
|
+
version: 0.7.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- spec/blip.rb
|
70
70
|
- spec/dsl/blap.rb
|
71
71
|
- spec/dsl/blup.rb
|
72
|
+
- spec/dsl/recursive/slammer.rb
|
72
73
|
- spec/dsl/require-dsl_spec.rb
|
73
74
|
- spec/require_more_spec.rb
|
74
75
|
- spec/spec_helper.rb
|
@@ -112,6 +113,7 @@ test_files:
|
|
112
113
|
- spec/blip.rb
|
113
114
|
- spec/dsl/blap.rb
|
114
115
|
- spec/dsl/blup.rb
|
116
|
+
- spec/dsl/recursive/slammer.rb
|
115
117
|
- spec/dsl/require-dsl_spec.rb
|
116
118
|
- spec/require_more_spec.rb
|
117
119
|
- spec/spec_helper.rb
|