around_the_world 0.6.0.pre → 0.6.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27a886d37bde56a1c6edb2c15b966cda10a449c0212d5133e7678109ffe25d10
4
- data.tar.gz: 35bf0553fdf79e411fce5dc412075f3daff8d2e61eae3361525110f43f9e6b5a
3
+ metadata.gz: 5ad71c73cc26ec0d9e5690f03242530c9b56d5f2b54923866e341abab656ccd1
4
+ data.tar.gz: 5274bc644da8e1ecc75fd50fab63cb21f3f630c293eb5e40e5be9f159feacbcf
5
5
  SHA512:
6
- metadata.gz: 0673b719dc14327044758b00bc15419d2913b76b81393ebe4840bd9d22ba60f63d74842013b0c4aefdae0a23b232cb19b2b5fef84c5930e9e0bda3f36c72d56d
7
- data.tar.gz: 57612955ef4da508567167eea0c6398060b7a40992baf8a99cb84033e8981c62b43beda02e95d2b3070ebe89f632e8b9d67e8c4d69c930463f91c5c8c9b187f8
6
+ metadata.gz: 8da4f44efc3e95c39d1e30d435d1641faeb52f929c44d41e675ce076fd0a3698b45bd2a17ead4597f5c302dd85e4f506cc2930a1a1b1b37b3bbfac17f6a6adbb
7
+ data.tar.gz: 655b51406c29c5f6699bf375b201287e8cf71fed081ae49944f76a0cbfc24595d3b5567f61601f9168fcaa1872f738cc28f7d67be7ae7b0d2605bb45818eadc5
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative "around_the_world/errors"
4
4
  require_relative "around_the_world/method_wrapper"
5
- require_relative "around_the_world/rewrapper"
6
5
  require_relative "around_the_world/proxy_module"
7
6
  require_relative "around_the_world/version"
8
7
  require "active_support/concern"
@@ -60,32 +59,13 @@ module AroundTheWorld
60
59
  # @param method_name [Symbol]
61
60
  # @param :prevent_double_wrapping_for [Object]
62
61
  # If defined, this prevents wrapping the method twice for a given purpose. Accepts any argument.
63
- # @param :wrap_subclasses [Boolean]
64
- # If true, the given method will still be wrapped by the given block in subclasses that override the given method.
65
- # If false, subclasses that override the method will also override the wrapping block.
66
- # Default: false
67
- def around_method(method_name, prevent_double_wrapping_for: nil, wrap_subclasses: false, &block)
62
+ def around_method(method_name, prevent_double_wrapping_for: nil, &block)
68
63
  MethodWrapper.wrap(
69
64
  method_name: method_name,
70
65
  target: self,
71
66
  prevent_double_wrapping_for: prevent_double_wrapping_for,
72
- wrap_subclasses: wrap_subclasses,
73
67
  &block
74
68
  )
75
-
76
- descendants.each { |child| Rewrapper.rewrap(child, proxy_modules_for_subwrapping) }
77
- end
78
-
79
- def inherited(child)
80
- super
81
-
82
- Rewrapper.rewrap(child, proxy_modules_for_subwrapping)
83
- end
84
-
85
- private
86
-
87
- def proxy_modules_for_subwrapping
88
- ancestors.select { |mod| mod.is_a?(ProxyModule) && self < mod && mod.wraps_subclasses? }
89
69
  end
90
70
  end
91
71
  end
@@ -23,19 +23,14 @@ module AroundTheWorld
23
23
  # An identifier to define the proxy module's purpose in the ancestor tree.
24
24
  # A method can only be wrapped once for a given purpose, though it can be wrapped
25
25
  # again for other purposes, or for no given purpose.
26
- # @param :wrap_subclasses [Boolean]
27
- # If true, the given method will still be wrapped by the given block in subclasses that override the given method.
28
- # If false, subclasses that override the method will also override the wrapping block.
29
- # Default: false
30
26
  # @block The block that will be executed when the method is invoked.
31
27
  # Should always call super, at least conditionally.
32
- def initialize(method_name:, target:, prevent_double_wrapping_for: nil, wrap_subclasses: false, &block)
28
+ def initialize(method_name:, target:, prevent_double_wrapping_for: nil, &block)
33
29
  raise TypeError, "target must be a module or a class" unless target.is_a?(Module)
34
30
 
35
31
  @method_name = method_name.to_sym
36
32
  @target = target
37
33
  @prevent_double_wrapping_for = prevent_double_wrapping_for || nil
38
- @wrap_subclasses = wrap_subclasses
39
34
  @block = block
40
35
  end
41
36
 
@@ -50,16 +45,12 @@ module AroundTheWorld
50
45
 
51
46
  private
52
47
 
53
- attr_reader :prevent_double_wrapping_for, :wrap_subclasses, :block
48
+ attr_reader :prevent_double_wrapping_for, :block
54
49
 
55
50
  def prevent_double_wrapping?
56
51
  prevent_double_wrapping_for.present?
57
52
  end
58
53
 
59
- def wrap_subclasses?
60
- wrap_subclasses.present?
61
- end
62
-
63
54
  def ensure_method_defined!
64
55
  return if target.instance_methods(true).include?(method_name) || target.private_method_defined?(method_name)
65
56
 
@@ -95,7 +86,7 @@ module AroundTheWorld
95
86
 
96
87
  # @return [AroundTheWorld::ProxyModule] The proxy module upon which the method wrapper will be defined
97
88
  def proxy_module
98
- @proxy_module ||= proxy_module_with_purpose(method_name, target, prevent_double_wrapping_for, wrap_subclasses?)
89
+ @proxy_module ||= proxy_module_with_purpose(method_name, target, prevent_double_wrapping_for)
99
90
  end
100
91
  end
101
92
  end
@@ -13,16 +13,14 @@ module AroundTheWorld
13
13
 
14
14
  # @return [AroundTheWorld::ProxyModule] Either an already-defined proxy module for the given purpose,
15
15
  # or a new proxy module if one does not exist for the given purpose.
16
- def proxy_module_with_purpose(method_name, target, purpose, wrap_subclasses)
17
- existing_proxy_module_with_purpose(method_name, target, purpose, wrap_subclasses) ||
18
- ProxyModule.new(purpose: purpose, wrap_subclasses: wrap_subclasses?)
16
+ def proxy_module_with_purpose(method_name, target, purpose)
17
+ existing_proxy_module_with_purpose(method_name, target, purpose) ||
18
+ ProxyModule.new(purpose: purpose)
19
19
  end
20
20
 
21
- def existing_proxy_module_with_purpose(method_name, target, purpose, wrap_subclasses)
21
+ def existing_proxy_module_with_purpose(method_name, target, purpose)
22
22
  existing_proxy_modules(target).reverse_each.find do |ancestor|
23
- ancestor.for?(purpose) &&
24
- !ancestor.defines_proxy_method?(method_name) &&
25
- ancestor.wraps_subclasses? == wrap_subclasses
23
+ ancestor.for?(purpose) && !ancestor.defines_proxy_method?(method_name)
26
24
  end
27
25
  end
28
26
 
@@ -4,29 +4,23 @@ module AroundTheWorld
4
4
  class ProxyModule < Module
5
5
  attr_reader :purpose
6
6
 
7
- def initialize(purpose: nil, wrap_subclasses: false)
7
+ # @param :purpose [*] Any string, symbol or object that signifies a purpose for the ProxyModule,
8
+ # i.e. :memoization or SomeMemoizationGem.
9
+ def initialize(purpose: nil)
8
10
  @purpose = purpose unless purpose.blank?
9
- @wrap_subclasses = wrap_subclasses
10
11
  end
11
12
 
12
13
  def for?(purpose)
13
14
  self.purpose == purpose
14
15
  end
15
16
 
16
- def wraps_subclasses?
17
- wrap_subclasses.present?
18
- end
19
-
20
17
  def inspect
21
18
  "#<#{self.class.name}#{":#{purpose}" if purpose}>"
22
19
  end
23
20
 
21
+ # @return [Boolean] True if the ProxyModule defines aa method of the given name, regardless of its privacy.
24
22
  def defines_proxy_method?(method_name)
25
23
  instance_methods(true).include?(method_name.to_sym) || private_method_defined?(method_name.to_sym)
26
24
  end
27
-
28
- private
29
-
30
- attr_reader :wrap_subclasses
31
25
  end
32
26
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module AroundTheWorld
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.6.0.pre"
5
+ VERSION = "0.6.0.pre2"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: around_the_world
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.pre
4
+ version: 0.6.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Rettberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-21 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,7 +38,6 @@ files:
38
38
  - lib/around_the_world/method_wrapper.rb
39
39
  - lib/around_the_world/method_wrapper/proxy_creation.rb
40
40
  - lib/around_the_world/proxy_module.rb
41
- - lib/around_the_world/rewrapper.rb
42
41
  - lib/around_the_world/version.rb
43
42
  homepage: https://www.freshly.com
44
43
  licenses:
@@ -59,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
58
  - !ruby/object:Gem::Version
60
59
  version: 1.3.1
61
60
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.7.6
61
+ rubygems_version: 3.0.3
64
62
  signing_key:
65
63
  specification_version: 4
66
64
  summary: A metaprogramming module which allows you to wrap any method easily.
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_support/core_ext/array"
4
- require_relative "method_wrapper/proxy_creation"
5
-
6
- module AroundTheWorld
7
- class Rewrapper
8
- include MethodWrapper::ProxyCreation
9
-
10
- private_class_method :new
11
-
12
- class << self
13
- def rewrap(target, proxy_modules)
14
- new(target, proxy_modules).rewrap
15
- end
16
- end
17
-
18
- attr_reader :target, :proxy_modules
19
-
20
- def initialize(target, proxy_modules)
21
- @target = target
22
- @proxy_modules = Array.wrap(proxy_modules)
23
- end
24
-
25
- def rewrap
26
- proxy_modules.each do |mod|
27
- next if existing_proxy_modules(target).include?(mod)
28
-
29
- target.prepend mod
30
- end
31
- end
32
- end
33
- end