around_the_world 0.2.5 → 0.3.0

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: 6d0727321851d428fa841e62287b39c108fa8c18a3eedb5206785bd6ff6a59ab
4
- data.tar.gz: 213a3401591f3d70fc6341d91475747d08b241420e05e24fa989e47b0095e6da
3
+ metadata.gz: ae037956a90fb7dd64586ff7f8b8bb1f02da897011c265881dbe071dc6f42c14
4
+ data.tar.gz: 1457f469d63242d427188b15506f6161260c02398519184d33b246051d5b669b
5
5
  SHA512:
6
- metadata.gz: b1b20790c35b223c2499fdd542695e9283a001f6b18c38f3a9ed4eb31271e68580c09275c16f309e9281ce55213e39c87668f8f88fdd828f305313c88b77f923
7
- data.tar.gz: eed8950132f53c6802892e7028b21ecff8111950e1b3c0dea61e01c3ff30c8230b848620d72fbad1926a4475412fc1e75ebee935ed7a90aeb703ff180fec9cfe
6
+ metadata.gz: 8e978961b7b9012e53bf9eeeda5f8efbb65bb6b4595c1585f8b89f98d0ef4a128fdfff849f3ed22bc8d5290f65a7134f85e35e4c22873e9ea5421b64c8db9349
7
+ data.tar.gz: 805e10ccc80702bb5dc8861c8eb7f659e7e7320159c852f4b58054389a27bb179d7b89212f27679186599211bb04a5e0aa9b1b8118e410b8da3216f0659f17eb
@@ -1,7 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "around_the_world/version"
3
+ require_relative "around_the_world/version"
4
+ require_relative "around_the_world/errors"
5
+ require "active_support/concern"
4
6
 
5
7
  module AroundTheWorld
6
- # Your code goes here...
8
+ extend ActiveSupport::Concern
9
+
10
+ class_methods do
11
+ protected
12
+
13
+ # Defines a method that gets called +around+ the given instance method.
14
+ #
15
+ # @example
16
+ # class SomeClass
17
+ # around_method :dont_look_in_here, "DoesAThing" do
18
+ # things_happened = super
19
+ #
20
+ # if things_happened
21
+ # puts "Something happened!"
22
+ # else
23
+ # puts "Nothing to see here..."
24
+ # end
25
+ # end
26
+ #
27
+ # def dont_look_in_here
28
+ # do_some_things
29
+ # end
30
+ # end
31
+ #
32
+ # SomeClass.new.dont_look_in_here
33
+ # => "Something happened!"
34
+ #
35
+ # @param method_name [Symbol]
36
+ # @param proxy_module_name [String] The camelized name of a custom module to place the wrapper method in.
37
+ # This is necessary to enable wrapping a single method more than once
38
+ # since a module cannot super to itself.
39
+ # It's recommended to name the module after what the method wrapper will do,
40
+ # for example LogsAnEvent for a wrapper method that logs something.
41
+ # Because of the potential for overriding previously wrapped methods, this
42
+ # parameter is required.
43
+ def around_method(method_name, proxy_module_name, &block)
44
+ proxy_module = around_method_proxy_module(proxy_module_name)
45
+ ensure_around_method_uniqueness!(method_name, proxy_module)
46
+
47
+ proxy_module.define_method(method_name, &block)
48
+ prepend proxy_module unless ancestors.include?(proxy_module)
49
+ end
50
+
51
+ private
52
+
53
+ def around_method_proxy_module(proxy_module_name)
54
+ namespaced_proxy_module_name = "#{self}::#{proxy_module_name}"
55
+
56
+ const_set(proxy_module_name, Module.new) unless const_defined?(namespaced_proxy_module_name)
57
+
58
+ const_get(namespaced_proxy_module_name)
59
+ end
60
+
61
+ def ensure_around_method_uniqueness!(method_name, proxy_module)
62
+ return unless proxy_module.instance_methods.include?(method_name.to_sym)
63
+
64
+ raise DoubleWrapError, "Module #{proxy_module} already defines the method :#{method_name}"
65
+ end
66
+ end
7
67
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AroundTheWorld
4
+ class DoubleWrapError < StandardError; end
5
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module AroundTheWorld
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.2.5"
5
+ VERSION = "0.3.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: around_the_world
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Rettberg
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-10-03 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.6
13
27
  description: Why metaprogram like a chump when you can do it like a champ!
14
28
  email:
15
29
  - allen.rettberg@freshly.com
@@ -20,6 +34,7 @@ files:
20
34
  - LICENSE.txt
21
35
  - README.md
22
36
  - lib/around_the_world.rb
37
+ - lib/around_the_world/errors.rb
23
38
  - lib/around_the_world/version.rb
24
39
  homepage: https://www.freshly.com
25
40
  licenses: