require-magic 0.4.1 → 0.5.0

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/README.rdoc CHANGED
@@ -11,31 +11,33 @@ require 'require_magic'
11
11
  # alternatively to only include require_dsl
12
12
  require 'require_dsl'
13
13
 
14
- Require.magic [path relative to current file location] do |magic|
14
+ Folder.enter [path relative to current file location] do |folder|
15
15
  # from new location, enter a subdir
16
- magic.enter [subdir] do |path|
17
- magic.require_all('**/*.rb').except(/sound\/*.rb/).require
16
+ folder.enter [subdir] do |path|
17
+ folder.all('**/*.rb').except(/sound\/*.rb/).require
18
18
  end
19
19
 
20
20
  # from new location, enter a subdir
21
- magic.enter [another subdir] do |path|
21
+ folder.enter [another subdir] do |path|
22
22
  # use file blobs here
23
- magic.require_all('**/*.rb').require
23
+ folder.all('**/*.rb').require
24
24
  end
25
25
 
26
26
  # from new location, enter a subdir
27
- magic.enter [yet another subdir] do |path|
27
+ folder.enter [yet another subdir] do |path|
28
28
  # matching and except are to be used as include and exclude filters
29
29
  # they each take a list containing regular expressions and strings
30
30
  # string arguments are postfixed with .rb internally if not present
31
- magic.require_all('blip/**/*.rb').matching(/_mixin.rb/, /.*\/power/).except(/sound/, /disco/).require
31
+ folder.all('blip/**/*.rb').matching(/_mixin.rb/, /.*\/power/).except(/sound/, /disco/).require
32
32
  end
33
33
 
34
34
  end
35
35
 
36
- Require.magic '../spec/fixtures' do |magic|
37
- magic.enter 'game' do |path|
38
- list = magic.require_all('**/*.rb')
36
+ # use current path as folder
37
+ Folder.enter do |folder|
38
+ folder.all('**/*.rb').require
39
+ folder.enter 'game' do |path|
40
+ list = folder.all('**/*.rb')
39
41
  # puts list.matching('sound', 'network').except(/sound/).show_require(:relative)
40
42
  list.matching('sound', 'network').except(/sound/).require
41
43
  end
data/lib/require-dsl.rb CHANGED
@@ -2,18 +2,24 @@ require 'rake'
2
2
  require 'fileutils'
3
3
  require 'util/util'
4
4
 
5
- module Require
5
+ module Folder
6
6
 
7
- def self.magic(path, &block)
8
- yield Magic.new path
7
+ def self.enter(path = '.', &block)
8
+ m = Magic.new
9
+ m.enter path
10
+ yield m
11
+ m.dir_stack.pop
9
12
  end
10
13
 
11
14
  module MagicList
12
15
  attr_accessor :base_path
13
16
  attr_accessor :rel_path
14
17
 
15
- def require(file)
16
- require file
18
+ def do_require
19
+ each do |file|
20
+ require file
21
+ end
22
+ self
17
23
  end
18
24
 
19
25
  def show_require(*options)
@@ -77,25 +83,25 @@ module Require
77
83
  attr_accessor :current_path
78
84
  attr_accessor :dir_stack
79
85
 
80
- def initialize(dir)
86
+ def initialize
81
87
  @dir_stack = []
82
88
  @current_path = FileUtils.pwd
83
- @current_path = enter(dir)
84
89
  end
85
90
 
86
91
  def enter(dir)
87
92
  FileUtils.cd dir
88
- dir_stack.push path = FileUtils.pwd
93
+ dir_stack.push path = FileUtils.pwd
89
94
  @current_path = path
90
95
  if block_given?
91
- yield path
92
- dir_stack.pop
93
- current_path = dir_stack.last
96
+ yield path
97
+ current_path = dir_stack.last
98
+ old_dir = dir_stack.last if dir_stack.pop
99
+ FileUtils.cd old_dir if old_dir
94
100
  end
95
101
  path
96
102
  end
97
103
 
98
- def require_all(*globs)
104
+ def all(*globs)
99
105
  list = FileList.new(globs)
100
106
  list.extend(MagicList)
101
107
  list.base_path = dir_stack.first
@@ -2,15 +2,32 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "RequireMagic" do
4
4
  it "works" do
5
- Require.magic '../spec/fixtures' do |magic|
6
- magic.enter 'game' do |path|
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")
5
+ Folder.enter '../spec/fixtures' do |folder|
6
+ folder.enter 'game' do |path|
7
+ list = folder.all('**/*.rb')
8
+ l1 = list.matching( 'sound', 'network').except(/sound/).do_require
9
+ l1_res = l1.show_require(:relative).inspect
10
+ l1_res.should include("network/network.rb")
10
11
 
11
12
  l2 = list.matching( '*/sound', 'network').show_require(:relative).inspect
12
13
  l2.should include("network/network.rb")
13
14
  end
14
15
  end
15
16
  end
17
+
18
+ it "works with base folder " do
19
+ Folder.enter do |folder|
20
+ puts folder.current_path
21
+ folder.enter 'game' do |path|
22
+ list = folder.all('**/*.rb')
23
+ l1 = list.matching( 'sound', 'network').except(/sound/).show_require(:relative).inspect
24
+ l1.should include("network/network.rb")
25
+
26
+ l2 = list.matching( '*/sound', 'network').show_require(:relative).inspect
27
+ l2.should include("network/network.rb")
28
+ end
29
+ end
30
+ end
31
+
32
+
16
33
  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.1
4
+ version: 0.5.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-02 00:00:00 -04:00
12
+ date: 2010-03-03 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15