require-me 0.6.2 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Includes a DSL for requiring files and folders and some also some static utility functions which can be used in combination.
4
4
  These tools in combination facilitates managing requiring various subfolder structures.
5
- FIXED
6
5
 
7
6
  ## Require DSL ##
8
7
 
@@ -57,7 +56,28 @@ Folder.enter do |folder| # use current path as folder
57
56
  puts list.matching('sound', 'network').except(/sound/).show_require(:relative)
58
57
  list.matching('sound', 'network').except(/sound/).do_require
59
58
  end
59
+ end
60
+ </pre>
61
+
62
+ Using 'require_me' method #
63
+
64
+ <pre>
65
+
66
+ # lib/gamer.rb
67
+ Folder.require_me '../fixtures/game/game.rb'
68
+ Folder.enter '../fixtures/game' do |f|
69
+ f.require_me 'game.rb'
70
+ end
71
+
72
+ # Set context in block using 'enter_here' method
73
+
74
+ # fixtures/game/game.rb
75
+ # ensure context is set relative to here for require statements within block
76
+ Folder.enter_here(__FILE__) do
77
+ # require graphics within the game folder!
78
+ Folder.require_me 'graphics/graphics'
60
79
  end
80
+
61
81
  </pre>
62
82
 
63
83
  ## Static helpers ##
data/lib/playground.rb CHANGED
@@ -6,4 +6,6 @@ end
6
6
 
7
7
  run "A" do |a|
8
8
  puts a * 2
9
- end
9
+ end
10
+
11
+ puts File.dirname(__FILE__)
data/lib/require-dsl.rb CHANGED
@@ -13,17 +13,44 @@ module Folder
13
13
  m.exit
14
14
  end
15
15
 
16
+ def self.enter_here(file, &block)
17
+ m = Magic.new
18
+ path = File.dirname(file)
19
+ m.enter path
20
+ if block_given?
21
+ yield m
22
+ end
23
+ m.exit
24
+ end
25
+
26
+
16
27
  def self.require_all(*folders)
17
28
  return Magic.new.all.dup.extend(MagicList).do_require if folders.empty?
18
29
  folders.each do |folder|
19
- enter folder do |f|
30
+ enter folder do |f|
20
31
  f.all.dup.extend(MagicList).do_require
21
32
  end
22
33
  end
23
34
  end
24
35
 
36
+ def self.show_require_all(*folders)
37
+ return Magic.new.all.dup.extend(MagicList).show_require if folders.empty?
38
+ folders.each do |folder|
39
+ enter folder do |f|
40
+ f.all.dup.extend(MagicList).show_require
41
+ end
42
+ end
43
+ end
25
44
 
26
45
 
46
+ def self.here(file)
47
+ FileUtils.cd File.dirname(file)
48
+ self
49
+ end
50
+
51
+ def self.require_me(*files)
52
+ return Magic.new.all(files).dup.extend(MagicList).do_require
53
+ end
27
54
 
28
55
  module MagicList
29
56
  attr_accessor :base_path
@@ -40,7 +67,7 @@ module Folder
40
67
  each do |f|
41
68
  if options.include? :relative
42
69
  file_path = File.join(rel_path, f)
43
- path = Require::Dir.relative_path(base_path, file_path)
70
+ path = Require::Directory.relative_path(base_path, file_path)
44
71
  end
45
72
  path = File.join(base_path, f) if !options.include? :relative
46
73
  path
@@ -101,6 +128,10 @@ module Folder
101
128
  @dir_stack = []
102
129
  @current_path = FileUtils.pwd
103
130
  end
131
+
132
+ def to_s
133
+ "path: #{current_path}, directory stack: #{dir_stack.inspect}"
134
+ end
104
135
 
105
136
  def enter(dir)
106
137
  path = FileUtils.pwd
@@ -139,6 +170,10 @@ module Folder
139
170
  end
140
171
  end
141
172
  end
173
+
174
+ def require_me(*files)
175
+ return all(files).dup.extend(MagicList).do_require
176
+ end
142
177
 
143
178
  end
144
179
  end
data/lib/require-me.rb CHANGED
@@ -84,7 +84,7 @@ protected
84
84
  includes_rexp = options[:include]
85
85
  excludes_rexp = options[:exclude]
86
86
 
87
- Dir.glob(path).each {|f|
87
+ ::Dir.glob(path).each {|f|
88
88
  next if excludes_rexp && match(f, excludes_rexp)
89
89
  if !includes_rexp || match(f, includes_rexp)
90
90
  puts_trace "require: #{f}", options
data/lib/util/util.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
 
3
3
  module Require
4
- module Dir
4
+ module Directory
5
5
  def self.relative_path(base_path, path)
6
6
  path.gsub! /#{Regexp.escape base_path}/
7
7
  p1 = Pathname.new base_path
@@ -3,18 +3,17 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "RequireMagic" do
4
4
  it "Folder.enter works " do
5
5
  puts FileUtils.pwd
6
- Folder.enter 'fixtures/game' do |folder|
7
- puts "Current 1:" + folder.current_path
6
+ Folder.enter '../fixtures/game' do |folder|
7
+ # puts "Current 1:" + folder.current_path
8
8
  end
9
- Folder.enter('fixtures/game') do |folder|
10
- puts "Current 2:" + folder.current_path
9
+ Folder.enter('../fixtures/game') do |folder|
10
+ # puts "Current 2:" + folder.current_path
11
11
  end
12
12
  end
13
13
 
14
14
  it "just works " do
15
- Folder.enter 'fixtures' do |folder| # oops!
15
+ Folder.enter '../fixtures' do |folder| # oops!
16
16
  folder.enter 'game' do |f|
17
- puts f
18
17
  list = folder.all('**/*.rb')
19
18
  l1 = list.matching( 'sound', 'network').except(/sound/).do_require
20
19
  l1_res = l1.show_require(:relative).inspect
@@ -27,28 +26,31 @@ describe "RequireMagic" do
27
26
  end
28
27
 
29
28
  it "works with require_all " do
30
- Folder.enter('fixtures/game') do |folder|
31
- puts "Current 1:" + folder.current_path
29
+ Folder.enter('../fixtures/game') do |folder|
30
+ # puts "Current 1:" + folder.current_path
32
31
  folder.require_all 'graphics', 'network', 'sound'
33
32
  end
34
33
  end
35
34
 
36
35
  it "works with require_all " do
37
- Folder.enter 'fixtures' do |f|
36
+ Folder.require_me '../fixtures/game/game.rb'
37
+
38
+ Folder.enter '../fixtures/game' do |f|
38
39
  f.require_all
40
+ f.require_me 'game.rb'
39
41
  end
40
42
  end
41
43
 
42
44
  it "works with require_all " do
43
- Folder.require_all 'fixtures'
45
+ Folder.require_all '../fixtures'
44
46
  end
45
47
 
46
48
 
47
49
  it "works with base folder " do
48
- Folder.enter 'fixtures' do |folder|
49
- puts "Current 2:" + folder.current_path
50
+ Folder.enter '../fixtures' do |folder|
51
+ # puts "Current 2:" + folder.current_path
50
52
  folder.enter 'game' do |f|
51
- puts f
53
+ # puts f
52
54
  f.require_all
53
55
  list = f.all # ('**/*.rb')
54
56
  l1 = list.matching( 'sound', 'network').except(/sound/).show_require(:relative).inspect
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "static folder functions" do
4
+ it "show work with here" do
5
+ Folder.here(__FILE__).require_me '../fixtures/game/game.rb'
6
+ end
7
+
8
+ it "show work with require_me" do
9
+ Folder.require_me '../fixtures/game/game.rb'
10
+ end
11
+
12
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'spec'))
3
4
  # require 'require-dsl'
4
5
  require 'require-me'
5
6
  require 'rspec'
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: require-me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 6
8
+ - 4
9
+ version: 0.6.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Kristian Mandrup
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-06 00:00:00 -04:00
17
+ date: 2010-03-18 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -42,27 +47,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
47
  requirements:
43
48
  - - ">="
44
49
  - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
45
52
  version: "0"
46
- version:
47
53
  required_rubygems_version: !ruby/object:Gem::Requirement
48
54
  requirements:
49
55
  - - ">="
50
56
  - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
51
59
  version: "0"
52
- version:
53
60
  requirements: []
54
61
 
55
62
  rubyforge_project:
56
- rubygems_version: 1.3.5
63
+ rubygems_version: 1.3.6
57
64
  signing_key:
58
65
  specification_version: 3
59
66
  summary: Facilitates requiring select ruby files in folders
60
67
  test_files:
61
- - spec/fixtures/game/game.rb
62
- - spec/fixtures/game/graphics/graphics.rb
63
- - spec/fixtures/game/network/network.rb
64
- - spec/fixtures/game/sound/sound.rb
65
68
  - spec/require-dsl_spec.rb
69
+ - spec/require_more_spec.rb
66
70
  - spec/spec_helper.rb
67
71
  - test/test_require_folder.rb
68
72
  - test/test_require_folders.rb
@@ -1 +0,0 @@
1
- puts "Game was included"
@@ -1 +0,0 @@
1
- puts "Graphics was included"
@@ -1 +0,0 @@
1
- puts "Network was included"
@@ -1 +0,0 @@
1
- puts "Sound was included"