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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e880dacf65e19267ebe16ba66d5ec85759f8e17d
4
- data.tar.gz: 7bd498ea658d2cff0b13207a27d98df96e740442
3
+ metadata.gz: 25b327952ba8a139e5c81f640b5d7100f6daabf5
4
+ data.tar.gz: 234c99e407ef28df46bb024a8656e5a1bce5c19b
5
5
  SHA512:
6
- metadata.gz: 8b4f4ce971e0f34b25190b69f67c1df97fe6e9b8ce1960d4ce10b2ec5e988f1b74187a0ef9882553be2a4aedd179220534d8e822a0f57c1d5cd068a1862e824f
7
- data.tar.gz: fd4f4fdf322c535abea6f95d50ac02dcf3731f3aaa153b12729d2d37acd50b0ee04dca8432132c0adc083760b482e4f42cd081cd9dbc7ea4fc9684034752d017
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, only: [:name, :from_spec]
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, Example::MixinUsableSpecUsed, Object, Kernel, BasicObject] (ruby -v 2.3.0)
101
+ Example.ancestors # => [Example, Mixin, Mixin::UsableSpec, Object, Kernel, BasicObject] (ruby -v 2.3.0)
102
102
  ```
103
103
 
104
- Notice that Usable assigns the modified module to a constant with the same name as the given module, but with "Used" appended.
105
- The main module and the spec were both included, but `Mixin` was not modified, so it didn't need a new name.
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
@@ -62,7 +62,8 @@ end
62
62
 
63
63
  class Example
64
64
  extend Usable
65
- usable Mixin, only: [:name, :from_spec]
65
+ usable Mixin
66
+ usable VersionMixin, max_versions: 10
66
67
  end
67
68
 
68
69
  Model.usable PersistenceOverride, method: 'prepend'
@@ -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).dup
11
+ @copy = mod.const_get(:UsableSpec)
12
12
  @name = "#{mod.name}UsableSpec"
13
13
  else
14
- @copy = mod.dup
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
- def call
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
- target.send :remove_const, const_name if target.const_defined? const_name, false
38
- target.const_set const_name, copy
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
@@ -1,3 +1,3 @@
1
1
  module Usable
2
- VERSION = "1.3.0".freeze
2
+ VERSION = "1.3.1".freeze
3
3
  end
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{A simple way to mount and configure your modules. Usable gives you control over which methods are included.}
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.0
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-02-24 00:00:00.000000000 Z
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: A simple way to mount and configure your modules. Usable gives you control
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: []