usable 1.3.0 → 1.3.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.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/bin/console +2 -1
- data/lib/usable/mod_extender.rb +13 -13
- data/lib/usable/version.rb +1 -1
- data/usable.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25b327952ba8a139e5c81f640b5d7100f6daabf5
|
4
|
+
data.tar.gz: 234c99e407ef28df46bb024a8656e5a1bce5c19b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed4caf302df5b5f543f31ab9e15bae983d6366ee4c07a71eed728551e6bc22a5d96a1d25eaef5f54e9c513c0195b6773f72f2c044ee1fc49ae2fd3db81e8300d
|
7
|
+
data.tar.gz: b0232a418c5b063d47671ce3944ae6bb4dbbda93d3c278f32474e4595620bdb7ec9ebd8ea3c49cc11738e27d1865e96e068d6a6018c798f99435a9bb0c1f83db
|
data/README.md
CHANGED
@@ -92,17 +92,24 @@ end
|
|
92
92
|
|
93
93
|
class Example
|
94
94
|
extend Usable
|
95
|
-
usable Mixin
|
95
|
+
usable Mixin
|
96
96
|
end
|
97
97
|
|
98
98
|
Example.new.from_spec # => "can be excluded"
|
99
99
|
Example.new.from_mixin # => "always here"
|
100
100
|
Example.new.name # => "defined by Mixin"
|
101
|
-
Example.ancestors # => [Example, Mixin,
|
101
|
+
Example.ancestors # => [Example, Mixin, Mixin::UsableSpec, Object, Kernel, BasicObject] (ruby -v 2.3.0)
|
102
102
|
```
|
103
103
|
|
104
|
-
|
105
|
-
|
104
|
+
## Notes
|
105
|
+
|
106
|
+
If the given module is modified by the `:only` option, then Usable will duplicate the module so that it doesn't mutate
|
107
|
+
it globally. Duplicating a module returns an anonymous module. But anonymous mods in the ancestor list can be confusing.
|
108
|
+
So Usable gives the modified module a name, which is the same name as the original module but with "Used" appended.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
Mixin => MixinUsed
|
112
|
+
```
|
106
113
|
|
107
114
|
## Installation
|
108
115
|
|
data/bin/console
CHANGED
data/lib/usable/mod_extender.rb
CHANGED
@@ -1,29 +1,27 @@
|
|
1
1
|
module Usable
|
2
2
|
class ModExtender
|
3
3
|
attr_reader :name
|
4
|
-
attr_accessor :copy, :mod, :options
|
4
|
+
attr_accessor :copy, :mod, :options, :unwanted
|
5
5
|
|
6
6
|
def initialize(mod, options = {})
|
7
7
|
@mod = mod
|
8
8
|
@options = options
|
9
9
|
@options[:method] ||= :include
|
10
10
|
if has_spec?
|
11
|
-
@copy = mod.const_get(:UsableSpec)
|
11
|
+
@copy = mod.const_get(:UsableSpec)
|
12
12
|
@name = "#{mod.name}UsableSpec"
|
13
13
|
else
|
14
|
-
@copy = mod
|
14
|
+
@copy = mod
|
15
15
|
@name = mod.name
|
16
16
|
end
|
17
|
+
@unwanted = options[:only] ? @copy.instance_methods - Array(options[:only]) : []
|
18
|
+
if @unwanted.any?
|
19
|
+
@copy = @copy.dup
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
|
-
|
20
|
-
override
|
21
|
-
copy
|
22
|
-
end
|
23
|
-
|
24
|
-
# @note Destructive, as it changes the dup'd mod
|
23
|
+
# @note Destructive, as it changes @copy
|
25
24
|
def override
|
26
|
-
unwanted = options[:only] ? copy.instance_methods - Array(options[:only]) : []
|
27
25
|
unwanted.each do |method_name|
|
28
26
|
copy.send :remove_method, method_name
|
29
27
|
end
|
@@ -32,10 +30,12 @@ module Usable
|
|
32
30
|
# @description Directly include a module whose methods you want made available in +usable_config.available_methods+
|
33
31
|
# Gives the module a name when including so that it shows up properly in the list of ancestors
|
34
32
|
def use!(target)
|
35
|
-
const_name = "#{mod_name}Used"
|
36
33
|
override
|
37
|
-
|
38
|
-
|
34
|
+
if copy.name.nil?
|
35
|
+
const_name = "#{mod_name}Used"
|
36
|
+
target.send :remove_const, const_name if target.const_defined? const_name, false
|
37
|
+
target.const_set const_name, copy
|
38
|
+
end
|
39
39
|
target.usable_config.modules << copy
|
40
40
|
target.send options[:method], copy
|
41
41
|
end
|
data/lib/usable/version.rb
CHANGED
data/usable.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["arebuckley@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Mounts and configures modules}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{An elegant way to mount and configure your modules. Usable gives you control over which methods are included.}
|
14
14
|
spec.homepage = "https://github.com/ridiculous/usable"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,8 +58,8 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '4'
|
61
|
-
description:
|
62
|
-
over which methods are included.
|
61
|
+
description: An elegant way to mount and configure your modules. Usable gives you
|
62
|
+
control over which methods are included.
|
63
63
|
email:
|
64
64
|
- arebuckley@gmail.com
|
65
65
|
executables: []
|