acls 1.1.1 → 1.1.2

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -2
  3. data/lib/acls/loader.rb +12 -12
  4. data/lib/acls/tree.rb +4 -0
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 575f79d69190c7e708e4e2609e216cd8db243a6d
4
- data.tar.gz: e720eac597e838e00015ba9edb1a104b587142a1
3
+ metadata.gz: 371e1095e948bc0bb96b66fd7e3b340572c98d8c
4
+ data.tar.gz: c936a33a329ef81e344dc884edae92f43028d8fd
5
5
  SHA512:
6
- metadata.gz: f1c8381ffe8380021dfc0f430639283a994901e2fb42e2cbce5d396fedac86ed05f5cb06107ff71f8497106b2cfc01f8496c359a0bd98185388e0c14ba9cbd16
7
- data.tar.gz: 5569fec00b72b029daec5a6f3ae49d37eb640790a2262504fe2de7e3d0e976c96f187a30c1025b96d0009dc9784e2632bbd40d0d4481f00202cf452c9a1fc076
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 string
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 path results in a successful match on the regexp.
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
- trees = build_trees(paths, opts)
7
- autoload_magic(trees, default_opts.merge(opts))
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
- 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
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 autoload_magic(trees, opts)
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.name
71
+ return true if pattern == File.basename(tree.path, ".rb")
72
72
  else
73
- return true if pattern.match(tree.name)
73
+ return true if pattern.match(tree.path)
74
74
  end
75
75
  end
76
76
  false
data/lib/acls/tree.rb CHANGED
@@ -16,6 +16,10 @@ module ACLS
16
16
  child
17
17
  end
18
18
 
19
+ def path
20
+ @source || @directory
21
+ end
22
+
19
23
  def to_s
20
24
  "name: #{@name}, source: #{@source}, directory: #{@directory}, parent: #{@parent}, children: #{@children.length}"
21
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kolo Rahl