acls 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -2
- data/lib/acls/loader.rb +12 -12
- data/lib/acls/tree.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 371e1095e948bc0bb96b66fd7e3b340572c98d8c
|
4
|
+
data.tar.gz: c936a33a329ef81e344dc884edae92f43028d8fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea9822b078d0324cd692311c652cdcd3dd554840d67d13152d41931ecf935c615d28ceb6347f2fdea9f39534d05bc6f4d102477835ba47be3cd5b637e96433e
|
7
|
+
data.tar.gz: ffc5b05d140e0f0158abbfb5514c1c622c8e4fce7a79ceb2d90b28c90b3642151d8f04a9ce5744f6f895d84db80ce795d2d85e970eb2961ddf5512836c4d791c
|
data/README.md
CHANGED
@@ -78,13 +78,28 @@ Options available:
|
|
78
78
|
values, the root directory is not a namespace and everything falls under the
|
79
79
|
`Object` namespace.
|
80
80
|
- `exclude`: Must be a collection of strings and/or regexps. For each string in
|
81
|
-
the collection, files are excluded from autoloading if they match the
|
81
|
+
the collection, files are excluded from autoloading if they match the _name_
|
82
82
|
exactly. For each regexp in the collection, files are excluded from
|
83
|
-
autoloading if the
|
83
|
+
autoloading if the _path_ results in a successful match on the regexp.
|
84
84
|
- `immediate`: Must be a collection of strings and/or regexps. Follows the same
|
85
85
|
conditional pattern as `exclude`, but on a match this will immediate load the
|
86
86
|
file via `load` instead of deferring it using `autoload`.
|
87
87
|
|
88
|
+
### Path vs Name
|
89
|
+
|
90
|
+
When talking about matching, there are two attributes: _names_ and _paths_.
|
91
|
+
|
92
|
+
A _name_ is the base file or directory name, without the Ruby file extension (if
|
93
|
+
it has one). e.g. `lib/foobar.rb` would have a _name_ of `foobar`.
|
94
|
+
|
95
|
+
A _path_ is the full path to a file or directory. e.g. `lib/foobar.rb`,
|
96
|
+
`lib/sub/directory`.
|
97
|
+
|
98
|
+
Strings tend to match against names, because names are shorter and strings are
|
99
|
+
meant for simple matching. Regexps tend to match against paths because a path
|
100
|
+
contains more information and regexps allow you to have more detailed control
|
101
|
+
over the matching conditions.
|
102
|
+
|
88
103
|
## Feature List
|
89
104
|
|
90
105
|
### Core
|
data/lib/acls/loader.rb
CHANGED
@@ -3,8 +3,8 @@ module ACLS
|
|
3
3
|
class << self
|
4
4
|
# Use one or more paths to autoload a set of Ruby source files.
|
5
5
|
def auto(paths, opts={})
|
6
|
-
|
7
|
-
|
6
|
+
opts = default_opts.merge(opts)
|
7
|
+
autoload_trees(build_trees(paths, opts), opts)
|
8
8
|
end
|
9
9
|
|
10
10
|
def default_opts
|
@@ -30,16 +30,16 @@ module ACLS
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def autoload_root(tree, opts)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
root = Object
|
34
|
+
if opts[:root_ns].is_a?(TrueClass)
|
35
|
+
root = submodule(root, File.basename(tree.directory).camelize)
|
36
|
+
elsif opts[:root_ns].is_a?(String)
|
37
|
+
opts[:root_ns].split('::').each { |ns| root = submodule(root, ns) }
|
38
|
+
end
|
39
|
+
root
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def autoload_trees(trees, opts)
|
43
43
|
trees.map do |tree|
|
44
44
|
root = autoload_root(tree, opts)
|
45
45
|
tree.children.map do |node|
|
@@ -68,9 +68,9 @@ module ACLS
|
|
68
68
|
def exclude?(mod, tree, opts)
|
69
69
|
opts[:exclude].each do |pattern|
|
70
70
|
if pattern.is_a?(String)
|
71
|
-
return true if pattern == tree.
|
71
|
+
return true if pattern == File.basename(tree.path, ".rb")
|
72
72
|
else
|
73
|
-
return true if pattern.match(tree.
|
73
|
+
return true if pattern.match(tree.path)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
false
|
data/lib/acls/tree.rb
CHANGED