require-magic 0.4.0 → 0.4.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/lib/require-dsl.rb +19 -9
- data/spec/require-dsl_spec.rb +6 -2
- metadata +1 -1
data/lib/require-dsl.rb
CHANGED
@@ -39,27 +39,37 @@ module Require
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def except(*reg_exps)
|
42
|
-
self.
|
43
|
-
|
42
|
+
duplicate = self.dup.extend(MagicList)
|
43
|
+
duplicate.each do |file|
|
44
|
+
reg_exps.each {|re| duplicate.delete(file) if file.match(re) }
|
44
45
|
end
|
45
|
-
|
46
|
+
duplicate
|
46
47
|
end
|
47
48
|
|
48
49
|
def postfix_rb(str)
|
49
50
|
str << '.rb' if !str.include? '.rb'
|
50
51
|
end
|
52
|
+
|
53
|
+
def fix(str)
|
54
|
+
postfix_rb(str)
|
55
|
+
str = Regexp.escape(str)
|
56
|
+
str.gsub! '\*', '[a-zA-Z0-9\s_-]*'
|
57
|
+
str.gsub! '/', '\/'
|
58
|
+
str
|
59
|
+
end
|
51
60
|
|
52
61
|
def matching(*reg_exps)
|
62
|
+
duplicate = self.dup.extend(MagicList)
|
53
63
|
keep_list = []
|
54
|
-
each do |file|
|
64
|
+
duplicate.each do |file|
|
55
65
|
reg_exps.each do |re|
|
56
|
-
|
66
|
+
re = fix(re) if re.kind_of? String
|
57
67
|
keep_list << file if file.match(re)
|
58
68
|
end
|
59
69
|
end
|
60
|
-
reject_list = (
|
61
|
-
delete_these(reject_list)
|
62
|
-
|
70
|
+
reject_list = (duplicate - keep_list).flatten
|
71
|
+
duplicate.delete_these(reject_list)
|
72
|
+
duplicate
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
@@ -90,7 +100,7 @@ module Require
|
|
90
100
|
list.extend(MagicList)
|
91
101
|
list.base_path = dir_stack.first
|
92
102
|
list.rel_path = current_path
|
93
|
-
list
|
103
|
+
list.freeze
|
94
104
|
end
|
95
105
|
|
96
106
|
end
|
data/spec/require-dsl_spec.rb
CHANGED
@@ -4,8 +4,12 @@ describe "RequireMagic" do
|
|
4
4
|
it "works" do
|
5
5
|
Require.magic '../spec/fixtures' do |magic|
|
6
6
|
magic.enter 'game' do |path|
|
7
|
-
list = magic.require_all('**/*.rb')
|
8
|
-
|
7
|
+
list = magic.require_all('**/*.rb')
|
8
|
+
l1 = list.matching( 'sound', 'network').except(/sound/).show_require(:relative).inspect
|
9
|
+
l1.should include("network/network.rb")
|
10
|
+
|
11
|
+
l2 = list.matching( '*/sound', 'network').show_require(:relative).inspect
|
12
|
+
l2.should include("network/network.rb")
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|