around_the_world 0.22.3.1 → 0.22.4

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: 5d47dda2b6885706b13d013c72a336308128624438d92ba65fadc80f4a37082f
4
- data.tar.gz: 8786045a2b7bc0fdc8f131d650236c75c61d9367a58f392ce18f7bb961608a3f
3
+ metadata.gz: d57efe8236b3276024f645121baabaaae3ab8bd5cf6c44a66e3581d4cc165b3d
4
+ data.tar.gz: 1666143f74d1fa5b4b71ba11cde97a560c21c7105cdfa99dde608383b567f420
5
5
  SHA512:
6
- metadata.gz: ba980c40022b0f16ed6c81464c20237b598c7915a83e243b6c26a38f4f959aadf45777655100f557cea05c66d6ecc00aa66672a60f1aef1955307cd1070933f2
7
- data.tar.gz: a4c51fc4a06e4504b5911f0fb7b92015195d3043551b380e306c74e83c6003a46ce4e2269f9b4901c1efeaec91c447df52874169b0f62dc7dfff7480c7646907
6
+ metadata.gz: a67f26e3d3e62a88b3d2618e2ed1caf44c244b474b0a13a4efa1012a0577d29777f7b6585d1b67ea54368b7d5882d6d74e4311038dbe29ee6754667bf27f7552
7
+ data.tar.gz: 6da324801843a15e4e7de05bcc3b114577e75d84c09c178f404a7ed2f70a012f30362d9870c1de9a3b587943661aae8eff4335b12378148abb4193fcabbd90b3
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/concern"
4
+ require "active_support/core_ext/object/blank"
5
+ require "active_support/descendants_tracker"
6
+
3
7
  require_relative "around_the_world/errors"
4
8
  require_relative "around_the_world/method_wrapper"
5
9
  require_relative "around_the_world/proxy_module"
6
10
  require_relative "around_the_world/version"
7
- require "active_support/concern"
8
- require "active_support/core_ext/object/blank"
9
- require "active_support/descendants_tracker"
10
11
 
11
12
  module AroundTheWorld
12
13
  extend ActiveSupport::Concern
@@ -78,11 +79,14 @@ module AroundTheWorld
78
79
  # @param method_name [Symbol]
79
80
  # @param :prevent_double_wrapping_for [Object]
80
81
  # If defined, this prevents wrapping the method twice for a given purpose. Accepts any argument.
81
- def around_method(method_name, prevent_double_wrapping_for: nil, &block)
82
+ # @param :allow_undefined_method [Boolean] When false, an error is raised if the wrapped method is not
83
+ # explicitly defined by the target module or class. Default: false
84
+ def around_method(method_name, prevent_double_wrapping_for: nil, allow_undefined_method: false, &block)
82
85
  MethodWrapper.wrap(
83
86
  method_name: method_name,
84
87
  target: self,
85
88
  prevent_double_wrapping_for: prevent_double_wrapping_for,
89
+ allow_undefined_method: allow_undefined_method,
86
90
  &block
87
91
  )
88
92
  end
@@ -23,14 +23,17 @@ 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 :allow_undefined_method [Boolean] When false, an error is raised if the wrapped method is not
27
+ # explicitly defined by the target. Default: false
26
28
  # @block The block that will be executed when the method is invoked.
27
29
  # Should always call super, at least conditionally.
28
- def initialize(method_name:, target:, prevent_double_wrapping_for: nil, &block)
30
+ def initialize(method_name:, target:, prevent_double_wrapping_for: nil, allow_undefined_method: false, &block)
29
31
  raise TypeError, "target must be a module or a class" unless target.is_a?(Module)
30
32
 
31
33
  @method_name = method_name.to_sym
32
34
  @target = target
33
35
  @prevent_double_wrapping_for = prevent_double_wrapping_for || nil
36
+ @allow_undefined_method = allow_undefined_method
34
37
  @block = block
35
38
  end
36
39
 
@@ -45,13 +48,14 @@ module AroundTheWorld
45
48
 
46
49
  private
47
50
 
48
- attr_reader :prevent_double_wrapping_for, :block
51
+ attr_reader :prevent_double_wrapping_for, :allow_undefined_method, :block
49
52
 
50
53
  def prevent_double_wrapping?
51
54
  prevent_double_wrapping_for.present?
52
55
  end
53
56
 
54
57
  def ensure_method_defined!
58
+ return if allow_undefined_method
55
59
  return if target.instance_methods(true).include?(method_name) || target.private_method_defined?(method_name)
56
60
 
57
61
  raise MethodNotDefinedError, "#{target} does not define :#{method_name}"
@@ -2,5 +2,5 @@
2
2
 
3
3
  module AroundTheWorld
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.22.3.1"
5
+ VERSION = "0.22.4"
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.22.3.1
4
+ version: 0.22.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Rettberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-05 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -47,7 +47,7 @@ metadata:
47
47
  homepage_uri: https://github.com/Freshly/spicerack/tree/master/around_the_world
48
48
  source_code_uri: https://github.com/Freshly/spicerack/tree/master/around_the_world
49
49
  changelog_uri: https://github.com/Freshly/spicerack/blob/master/around_the_world/CHANGELOG.md
50
- documentation_uri: https://www.rubydoc.info/gems/around_the_world/0.22.3.1
50
+ documentation_uri: https://www.rubydoc.info/gems/around_the_world/0.22.4
51
51
  post_install_message:
52
52
  rdoc_options: []
53
53
  require_paths: