require-magic 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
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.each do |file|
43
- reg_exps.each {|re| self.delete(file) if file.match(re) }
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
- self
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
- postfix_rb(re) if re.kind_of? String
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 = (self - keep_list).flatten
61
- delete_these(reject_list)
62
- self
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
@@ -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
- puts list.matching( 'sound', 'network').except(/sound/).show_require(:relative).inspect.should include("network/network.rb")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: require-magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Mandrup