require-magic 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
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
- require 'require_magic'
10
-
11
- # alternatively to only include require_dsl
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
- * required_files = Require.base_path = File.dirname(__FILE__)
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
- * required_files = Require.folders('data')
63
+ <code>
64
+ required_files = Require.folders('data')
65
+ </code>
55
66
 
56
67
  Override base_path
57
- * required_files = Require.folders('data', {:base_path => File.dirname(__FILE__) + '/../my/path})
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
- * required_files = Require.folder 'data'
63
- * required_files = Require.folders 'data'
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
- * required_files = Require.recursive('data')
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
- * required_files = Require.recursive(['data', 'data2'])
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
- * required_files = Require.recursive(['data', 'data2'])
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
- * required_files = Require.folders(['data', 'data2'], {:folders => ['blip]})
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
- * required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :ignore_root_files => true})
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
- * required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :before})
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
- * required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :after})
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
- * required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :before})
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
@@ -101,7 +101,8 @@ module Folder
101
101
  path
102
102
  end
103
103
 
104
- def all(*globs)
104
+ def all(*globs)
105
+ globs = '**/*.rb' if globs.empty?
105
106
  list = FileList.new(globs)
106
107
  list.extend(MagicList)
107
108
  list.base_path = dir_stack.first
@@ -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
 
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Mandrup