require-me 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/lib/playground.rb +9 -0
- data/lib/require-dsl.rb +32 -13
- data/spec/require-dsl_spec.rb +26 -13
- metadata +3 -2
data/README.markdown
CHANGED
@@ -44,7 +44,7 @@ If no argument, current path is used as initial folder
|
|
44
44
|
require 'require-me' # include both the static require helpers and the DSL require language
|
45
45
|
|
46
46
|
Folder.enter do |folder| # use current path as folder
|
47
|
-
folder.enter 'game' do |f|
|
47
|
+
folder.enter 'game' do |f| # enter doesn't work with special folders '.' and '..' yet
|
48
48
|
folder.require_all # require all .rb files within this folder!
|
49
49
|
|
50
50
|
`# use static require functions`
|
data/lib/playground.rb
ADDED
data/lib/require-dsl.rb
CHANGED
@@ -5,11 +5,17 @@ require 'util/util'
|
|
5
5
|
module Folder
|
6
6
|
|
7
7
|
def self.enter(path = '.', &block)
|
8
|
-
m = Magic.new
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
m = Magic.new
|
9
|
+
puts "Path:#{path}"
|
10
|
+
paths = path.split('/')
|
11
|
+
puts paths
|
12
|
+
paths.each{|p| m.enter p}
|
13
|
+
if block_given?
|
14
|
+
yield m
|
15
|
+
end
|
16
|
+
puts "Path:#{path}"
|
17
|
+
path.split('/').each{|p| m.exit p }
|
18
|
+
end
|
13
19
|
|
14
20
|
module MagicList
|
15
21
|
attr_accessor :base_path
|
@@ -88,19 +94,27 @@ module Folder
|
|
88
94
|
@current_path = FileUtils.pwd
|
89
95
|
end
|
90
96
|
|
91
|
-
def enter(dir)
|
92
|
-
|
97
|
+
def enter(dir)
|
98
|
+
puts "cd #{dir}"
|
99
|
+
FileUtils.cd dir if !dir.empty?
|
93
100
|
dir_stack.push path = FileUtils.pwd
|
94
101
|
@current_path = path
|
95
102
|
if block_given?
|
96
|
-
yield self
|
97
|
-
|
98
|
-
old_dir = dir_stack.last if dir_stack.pop
|
99
|
-
FileUtils.cd old_dir if old_dir
|
103
|
+
yield self
|
104
|
+
exit(dir)
|
100
105
|
end
|
101
106
|
self
|
102
107
|
end
|
103
108
|
|
109
|
+
def exit(dir)
|
110
|
+
current_path = dir_stack.last
|
111
|
+
old_dir = dir_stack.last if dir_stack.pop
|
112
|
+
puts "cd .."
|
113
|
+
# FileUtils.cd old_dir if old_dir
|
114
|
+
FileUtils.cd '..'
|
115
|
+
end
|
116
|
+
|
117
|
+
|
104
118
|
def all(*globs)
|
105
119
|
globs = '**/*.rb' if globs.empty?
|
106
120
|
list = FileList.new(globs)
|
@@ -110,8 +124,13 @@ module Folder
|
|
110
124
|
list.freeze
|
111
125
|
end
|
112
126
|
|
113
|
-
def require_all
|
114
|
-
all.dup.extend(MagicList).do_require
|
127
|
+
def require_all(*folders)
|
128
|
+
return all.dup.extend(MagicList).do_require if folders.empty?
|
129
|
+
folders.each do |folder|
|
130
|
+
enter folder do |f|
|
131
|
+
f.all.dup.extend(MagicList).do_require
|
132
|
+
end
|
133
|
+
end
|
115
134
|
end
|
116
135
|
|
117
136
|
end
|
data/spec/require-dsl_spec.rb
CHANGED
@@ -1,24 +1,41 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "RequireMagic" do
|
4
|
-
it "works" do
|
5
|
-
|
4
|
+
it "Folder.enter works " do
|
5
|
+
puts FileUtils.pwd
|
6
|
+
Folder.enter 'fixtures/game' do |folder|
|
7
|
+
puts "Current 1:" + folder.current_path
|
8
|
+
end
|
9
|
+
Folder.enter('fixtures/game') do |folder|
|
10
|
+
puts "Current 2:" + folder.current_path
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "just works " do
|
15
|
+
Folder.enter 'fixtures' do |folder| # oops!
|
6
16
|
folder.enter 'game' do |f|
|
7
17
|
puts f
|
8
18
|
list = folder.all('**/*.rb')
|
9
19
|
l1 = list.matching( 'sound', 'network').except(/sound/).do_require
|
10
20
|
l1_res = l1.show_require(:relative).inspect
|
11
21
|
l1_res.should include("network/network.rb")
|
12
|
-
|
22
|
+
|
13
23
|
l2 = list.matching( '*/sound', 'network').show_require(:relative).inspect
|
14
24
|
l2.should include("network/network.rb")
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
18
|
-
|
19
|
-
it "works with
|
20
|
-
Folder.enter do |folder|
|
21
|
-
puts folder.current_path
|
28
|
+
|
29
|
+
it "works with require_all " do
|
30
|
+
Folder.enter('fixtures/game') do |folder|
|
31
|
+
puts "Current 1:" + folder.current_path
|
32
|
+
# f.require_all 'graphics', 'network', 'sound'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "works with base folder " do
|
37
|
+
Folder.enter 'fixtures' do |folder|
|
38
|
+
puts "Current 2:" + folder.current_path
|
22
39
|
folder.enter 'game' do |f|
|
23
40
|
puts f
|
24
41
|
f.require_all
|
@@ -27,13 +44,9 @@ describe "RequireMagic" do
|
|
27
44
|
l1.should include("network/network.rb")
|
28
45
|
|
29
46
|
l2 = list.matching( '*/sound', 'network').show_require(:relative).inspect
|
30
|
-
l2.should include("network/network.rb")
|
31
|
-
|
32
|
-
|
33
|
-
|
47
|
+
l2.should include("network/network.rb")
|
34
48
|
end
|
35
49
|
end
|
36
|
-
end
|
37
|
-
|
50
|
+
end
|
38
51
|
|
39
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: require-me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Mandrup
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-06 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,6 +23,7 @@ extra_rdoc_files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.markdown
|
25
25
|
files:
|
26
|
+
- lib/playground.rb
|
26
27
|
- lib/require-dsl.rb
|
27
28
|
- lib/require-me.rb
|
28
29
|
- lib/util/util.rb
|