require-magic 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -0
- data/VERSION +1 -1
- data/lib/require-magic.rb +2 -2
- data/require-magic.gemspec +3 -2
- data/test/test_require_magic.rb +16 -20
- data/test/test_require_magic_adv.rb +21 -14
- data/test/unit_test_require.rb +16 -0
- metadata +2 -1
data/README.rdoc
CHANGED
@@ -4,6 +4,43 @@ 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
|
8
|
+
See unit tests for demonstrations of how to use it:
|
9
|
+
|
10
|
+
To require all files within the top level folder 'data' (non-recursively)
|
11
|
+
* required_files = Require.folder('data')
|
12
|
+
|
13
|
+
The required_files returned is a list of the paths of the files that were required
|
14
|
+
|
15
|
+
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
|
16
|
+
* required_files = Require.folder('data')
|
17
|
+
|
18
|
+
|
19
|
+
To require all files within the top level folder 'data' recursively
|
20
|
+
* required_files = Require.rfolder('data')
|
21
|
+
|
22
|
+
To require all files within the top level folders 'data' and 'data2' (non-recursively)
|
23
|
+
* required_files = Require.rfolders(['data', 'data2'])
|
24
|
+
|
25
|
+
To require all files within the top level folders 'data' and 'data2' recursively
|
26
|
+
* required_files = Require.rfolders(['data', 'data2'])
|
27
|
+
|
28
|
+
To require files within the top level folders 'data' and 'data2' and also files within the subdirectory 'blip' if it exists
|
29
|
+
* required_files = Require.folders(['data', 'data2'], {:folders => ['blip]})
|
30
|
+
|
31
|
+
To require files within 'data/blip' and 'data2/blip' only
|
32
|
+
* required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :ignore_root_files => true})
|
33
|
+
|
34
|
+
To require files within 'data' and 'data2' first and then any files within the subdirectory 'blip' (default order)
|
35
|
+
* required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :before})
|
36
|
+
|
37
|
+
To require files within 'data/blip' and 'data2/blip' first and then any files within 'data' and 'data2' folders
|
38
|
+
* required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :after})
|
39
|
+
|
40
|
+
To require files within 'data' and 'data2' first and then any files within the subdirectory 'blip'
|
41
|
+
* required_files = Require.folders(['data', 'data2'], {:folders => ['blip], :root_files => :before})
|
42
|
+
|
43
|
+
|
7
44
|
== Note on Patches/Pull Requests
|
8
45
|
|
9
46
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/require-magic.rb
CHANGED
@@ -14,7 +14,7 @@ module Require
|
|
14
14
|
|
15
15
|
puts_trace "folder:: name: #{name}", options
|
16
16
|
|
17
|
-
if options[:root_files] == :before
|
17
|
+
if !options[:root_files] || options[:root_files] == :before
|
18
18
|
required_files << require_root_files(name, folder_list, path, options)
|
19
19
|
# options[:root] = false
|
20
20
|
required_files << require_folder_list(name, folder_list, options)
|
@@ -64,7 +64,7 @@ protected
|
|
64
64
|
else
|
65
65
|
includes_rexp = options[:include]
|
66
66
|
excludes_rexp = options[:exclude]
|
67
|
-
|
67
|
+
|
68
68
|
Dir.glob(path).each {|f|
|
69
69
|
next if excludes_rexp && match(f, excludes_rexp)
|
70
70
|
if !includes_rexp || match(f, includes_rexp)
|
data/require-magic.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{require-magic}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
@@ -39,7 +39,8 @@ Gem::Specification.new do |s|
|
|
39
39
|
"spec/require-magic_spec.rb",
|
40
40
|
"spec/spec_helper.rb",
|
41
41
|
"test/test_require_magic.rb",
|
42
|
-
"test/test_require_magic_adv.rb"
|
42
|
+
"test/test_require_magic_adv.rb",
|
43
|
+
"test/unit_test_require.rb"
|
43
44
|
]
|
44
45
|
|
45
46
|
if s.respond_to? :specification_version then
|
data/test/test_require_magic.rb
CHANGED
@@ -1,50 +1,46 @@
|
|
1
1
|
require 'require-magic'
|
2
|
-
require "
|
2
|
+
require "unit_test_require"
|
3
3
|
|
4
|
-
class TestFilter <
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@folders = ['data', 'data2']
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
## Nothing really
|
12
|
-
end
|
4
|
+
class TestFilter < UnitTestRequire
|
13
5
|
|
14
6
|
def test_require_folders
|
15
7
|
required_files = Require.folders(@folders)
|
16
8
|
|
17
|
-
found0 =
|
18
|
-
found1 =
|
19
|
-
|
9
|
+
found0 = match? required_files[0], 'data_a.rb'
|
10
|
+
found1 = match? required_files[1], 'data2/blap_a.rb'
|
11
|
+
|
20
12
|
assert_equal 2, required_files.size, "Should require 2 files"
|
21
|
-
|
22
|
-
|
13
|
+
assert found0, "Should require data_a.rb in /"
|
14
|
+
assert found1, "Should require blap_a.rb in /data"
|
23
15
|
end
|
24
16
|
|
25
17
|
def test_require_folders_recursive
|
26
18
|
options = {:recursive => true}
|
27
19
|
required_files = Require.folders(@folders, options)
|
28
|
-
assert_equal
|
20
|
+
assert_equal 5, required_files.size, "Should require 5 files"
|
29
21
|
end
|
30
22
|
|
31
|
-
def
|
23
|
+
def test_require_folders_recursive_include
|
32
24
|
options = {:recursive => true, :include => 'blip_'}
|
33
25
|
required_files = Require.folders(@folders, options)
|
34
26
|
assert_equal 2, required_files.size, "Should require 2 files"
|
35
27
|
end
|
36
28
|
|
37
|
-
def
|
29
|
+
def test_require_folders_recursive_exclude
|
38
30
|
options = {:recursive => true, :exclude => 'blip_'}
|
39
31
|
required_files = Require.folders(@folders, options)
|
40
|
-
assert_equal
|
32
|
+
assert_equal 3, required_files.size, "Should require 3 file"
|
41
33
|
end
|
42
34
|
|
43
|
-
def
|
35
|
+
def test_require_folders_recursive_default
|
44
36
|
options = {:folders => ['blip']}
|
45
37
|
required_files = Require.folders(@folders, options)
|
46
38
|
assert_equal 4, required_files.size, "Should require 4 files"
|
39
|
+
|
40
|
+
found0 = match? required_files[0], 'data_a.rb'
|
41
|
+
assert found0, "Should require root files such as 'data_a.rb' first"
|
47
42
|
end
|
43
|
+
|
48
44
|
|
49
45
|
end
|
50
46
|
|
@@ -1,17 +1,7 @@
|
|
1
1
|
require 'require-magic'
|
2
|
-
require "
|
2
|
+
require "unit_test_require"
|
3
3
|
|
4
|
-
class
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@folders = ['data', 'data2']
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
## Nothing really
|
12
|
-
end
|
13
|
-
|
14
|
-
|
4
|
+
class TestRequireAdv < UnitTestRequire
|
15
5
|
|
16
6
|
def test_require_folders_recursive
|
17
7
|
options = {:folders => ['blip'], :ignore_root_files => true}
|
@@ -23,17 +13,24 @@ class TestFilter < Test::Unit::TestCase
|
|
23
13
|
options = {:folders => ['blip'], :root_files => :before}
|
24
14
|
required_files = Require.folders(@folders, options)
|
25
15
|
assert_equal 4, required_files.size, "Should require 4 files"
|
16
|
+
|
17
|
+
root_first = match?(required_files[0], 'data_a.rb')
|
18
|
+
assert root_first, "First required file should be root file 'data_a.rb'"
|
26
19
|
end
|
27
20
|
|
28
|
-
def
|
21
|
+
def test_require_folders_root_folders_after
|
29
22
|
options = {:folders => ['blip'], :root_files => :after}
|
30
23
|
required_files = Require.folders(@folders, options)
|
31
24
|
assert_equal 4, required_files.size, "Should require 4 files"
|
25
|
+
|
26
|
+
root_last = match?(required_files[2], 'data_a.rb')
|
27
|
+
assert root_last, "Last required file of 'data' should be root file 'data_a.rb'"
|
32
28
|
end
|
33
29
|
|
34
30
|
def test_require_folders_root_folders_before_but_ignore
|
35
|
-
options = {:folders => ['blip'], :root_files => :
|
31
|
+
options = {:folders => ['blip'], :root_files => :before, :ignore_root_files => true}
|
36
32
|
required_files = Require.folders(@folders, options)
|
33
|
+
|
37
34
|
assert_equal 3, required_files.size, "Should require 3 files"
|
38
35
|
end
|
39
36
|
|
@@ -43,5 +40,15 @@ class TestFilter < Test::Unit::TestCase
|
|
43
40
|
assert_equal 3, required_files.size, "Should require 3 files"
|
44
41
|
end
|
45
42
|
|
43
|
+
def test_require_folders_recursive_data_root_folders_after
|
44
|
+
options = {:folders => ['blip'], :root_files => :after}
|
45
|
+
required_files = Require.folders('data', options)
|
46
|
+
assert_equal 3, required_files.size, "Should require 3 files"
|
47
|
+
|
48
|
+
root_last = match?(required_files[2], 'data_a.rb')
|
49
|
+
|
50
|
+
assert root_last, "Last required file should be root file 'data_a.rb'"
|
51
|
+
end
|
52
|
+
|
46
53
|
|
47
54
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
class UnitTestRequire < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@folders = ['data', 'data2']
|
7
|
+
end
|
8
|
+
|
9
|
+
def match?(expr, rexp)
|
10
|
+
!(expr =~ /#{Regexp.escape(rexp)}/).nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_me
|
14
|
+
assert true, "true"
|
15
|
+
end
|
16
|
+
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Mandrup
|
@@ -77,3 +77,4 @@ test_files:
|
|
77
77
|
- spec/spec_helper.rb
|
78
78
|
- test/test_require_magic.rb
|
79
79
|
- test/test_require_magic_adv.rb
|
80
|
+
- test/unit_test_require.rb
|