require-magic 0.5.0 → 0.5.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/README.rdoc +52 -33
- data/lib/require-dsl.rb +2 -1
- data/spec/require-dsl_spec.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -4,12 +4,11 @@ Utility functions to facilitate importing (require) ruby files in complex Ruby p
|
|
4
4
|
See unit tests in /test directory to see how to use the tools for the best effect.
|
5
5
|
Using this toolset should really simplify your require statements and make your application more flexible to change.
|
6
6
|
|
7
|
-
== USAGE
|
7
|
+
== USAGE
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# alternatively
|
12
|
-
require 'require_dsl'
|
9
|
+
<code>
|
10
|
+
require 'require_magic' # include both the old static require helpers and the DSL require language
|
11
|
+
require 'require_dsl' # alternatively only include require_dsl (the DSL language)
|
13
12
|
|
14
13
|
Folder.enter [path relative to current file location] do |folder|
|
15
14
|
# from new location, enter a subdir
|
@@ -29,6 +28,14 @@ Folder.enter [path relative to current file location] do |folder|
|
|
29
28
|
# they each take a list containing regular expressions and strings
|
30
29
|
# string arguments are postfixed with .rb internally if not present
|
31
30
|
folder.all('blip/**/*.rb').matching(/_mixin.rb/, /.*\/power/).except(/sound/, /disco/).require
|
31
|
+
|
32
|
+
folder.enter [subdir] do |path|
|
33
|
+
folder.enter [subdir] do |path|
|
34
|
+
folder.all('grusch/**/*.rb').require
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
folder.all.require
|
32
39
|
end
|
33
40
|
|
34
41
|
end
|
@@ -42,61 +49,73 @@ Folder.enter do |folder|
|
|
42
49
|
list.matching('sound', 'network').except(/sound/).require
|
43
50
|
end
|
44
51
|
end
|
52
|
+
</code>
|
45
53
|
|
46
|
-
|
47
|
-
== USAGE (Deprecated)
|
54
|
+
== Static helpers
|
48
55
|
See unit tests for demonstrations of how to use it:
|
49
56
|
|
50
|
-
Set basepath to use for require
|
51
|
-
|
57
|
+
# Set basepath to use for require
|
58
|
+
<code>
|
59
|
+
required_files = Require.base_path = File.dirname(__FILE__)
|
60
|
+
</code>
|
52
61
|
|
53
62
|
To require all files within the top level folder 'data' (non-recursively)
|
54
|
-
|
63
|
+
<code>
|
64
|
+
required_files = Require.folders('data')
|
65
|
+
</code>
|
55
66
|
|
56
67
|
Override base_path
|
57
|
-
|
68
|
+
<code>
|
69
|
+
required_files = Require.folders('data', {:base_path => File.dirname(__FILE__) + '/../my/path})
|
70
|
+
</code>
|
58
71
|
|
59
72
|
The required_files returned is a list of the paths of the files that were required
|
60
73
|
|
61
74
|
To require all files within the top level folder 'data' (non-recursively) and apply tracing to see output for the process of requiring the files
|
62
|
-
|
63
|
-
|
75
|
+
<code>
|
76
|
+
required_files = Require.folder 'data'
|
77
|
+
required_files = Require.folders 'data'
|
78
|
+
</code>
|
64
79
|
|
65
80
|
To require all files within the top level folder 'data' recursively
|
66
|
-
|
81
|
+
<code>
|
82
|
+
required_files = Require.recursive('data')
|
83
|
+
</code>
|
67
84
|
|
68
85
|
To require all files within the top level folders 'data' and 'data2' (non-recursively)
|
69
|
-
|
86
|
+
<code>
|
87
|
+
required_files = Require.recursive(['data', 'data2'])
|
88
|
+
</code>
|
70
89
|
|
71
90
|
To require all files within the top level folders 'data' and 'data2' recursively
|
72
|
-
|
91
|
+
<code>
|
92
|
+
required_files = Require.recursive(['data', 'data2'])
|
93
|
+
</code>
|
73
94
|
|
74
95
|
To require files within the top level folders 'data' and 'data2' and also files within the subdirectory 'blip' if it exists
|
75
|
-
|
96
|
+
<code>
|
97
|
+
required_files = Require.folders(['data', 'data2'], {:folders => ['blip]})
|
98
|
+
</code>
|
76
99
|
|
77
100
|
To require files within 'data/blip' and 'data2/blip' only, NOT including the root files
|
78
|
-
|
101
|
+
<code>
|
102
|
+
required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :ignore_root_files => true})
|
103
|
+
</code>
|
79
104
|
|
80
105
|
To require files within 'data' and 'data2' first and then AFTER any files within the subdirectory 'blip' (default order)
|
81
|
-
|
106
|
+
<code>
|
107
|
+
required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :before})
|
108
|
+
</code>
|
82
109
|
|
83
110
|
To require files within 'data/blip' and 'data2/blip' first and then AFTER any files within 'data' and 'data2' folders (the root files)
|
84
|
-
|
111
|
+
<code>
|
112
|
+
required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :after})
|
113
|
+
</code>
|
85
114
|
|
86
115
|
To require files within 'data' and 'data2' (the root files) first (BEFORE) and then any files within the subdirectory 'blip'
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
== Note on Patches/Pull Requests
|
91
|
-
|
92
|
-
* Fork the project.
|
93
|
-
* Make your feature addition or bug fix.
|
94
|
-
* Add tests for it. This is important so I don't break it in a
|
95
|
-
future version unintentionally.
|
96
|
-
* Commit, do not mess with rakefile, version, or history.
|
97
|
-
(if you want to have your own version, that is fine but
|
98
|
-
bump version in a commit by itself I can ignore when I pull)
|
99
|
-
* Send me a pull request. Bonus points for topic branches.
|
116
|
+
<code>
|
117
|
+
required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :before})
|
118
|
+
</code>
|
100
119
|
|
101
120
|
== Copyright
|
102
121
|
|
data/lib/require-dsl.rb
CHANGED
data/spec/require-dsl_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe "RequireMagic" do
|
|
19
19
|
Folder.enter do |folder|
|
20
20
|
puts folder.current_path
|
21
21
|
folder.enter 'game' do |path|
|
22
|
-
list = folder.all('**/*.rb')
|
22
|
+
list = folder.all # ('**/*.rb')
|
23
23
|
l1 = list.matching( 'sound', 'network').except(/sound/).show_require(:relative).inspect
|
24
24
|
l1.should include("network/network.rb")
|
25
25
|
|