easy_callbacks 0.0.1 → 0.1.0

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: cce1c2beaaac84b2bffb1e31f5050fd266a9579d
4
- data.tar.gz: 2a110c619bdd06c0bedbf78a7fb0e2cd6b10db03
3
+ metadata.gz: 78cd29e96e4f33597087840a931d11e87814ed37
4
+ data.tar.gz: 150a4c2f8d45946662ec580ec9bb0b030de92182
5
5
  SHA512:
6
- metadata.gz: 2aa984d05872a945035ce437e0469013bf71ad60022fe88a2b5e0dc8f70aa56b80a35a4df5c84e050765fe53dc877679ca59cdb84d70739327abda2d84c1568f
7
- data.tar.gz: b6183b1cc3fed10ee38d11e59c28a224c9edf92fa57f4c8fc843d501d9ce47a34716cce032848c1b0b313526a32add6f82e06865fab0b45bba9bc083401f7eda
6
+ metadata.gz: 2825eb20a91976a4aef8f578de2af31381edefb55a232e820761b5974682c56088dd7174dc20f3ce9cee49567f6849764fc623badc02e47bb4292a1840585ffc
7
+ data.tar.gz: 8a8f9402da6216a8eb3204b9df913cd840d6706f56103632982a81901891f92029e4a1f7fbdee00932c358b56bdfe14a00aabb3cf19b3ea753c16087317bc6e8
data/README.rdoc CHANGED
@@ -54,10 +54,11 @@ For anonymous callbacks:
54
54
 
55
55
  {
56
56
  class: SomeClass,
57
+ object: #<SomeClass:0x00000002b65ab0>,
57
58
  target: :some_method,
58
59
  type: :before,
59
60
  callback_name: nil,
60
- proc: '#<Proc:0x00000002655a20@...>'
61
+ proc: #<Proc:0x00000002655a20@...>
61
62
  }
62
63
 
63
64
  For around callbacks (with success):
@@ -81,9 +82,35 @@ For around callbacks (with error):
81
82
  callback_name: :do_it_around,
82
83
  proc: nil,
83
84
  return_type: :error,
84
- return_object: '#<StandardError: StandardError>'
85
+ return_object: #<StandardError: StandardError>
85
86
  }
86
87
 
88
+ == Singleton Classes Support
89
+
90
+ It works too:
91
+
92
+ class SomeClass
93
+
94
+ class << self
95
+
96
+ def some_method(some_arg)
97
+ puts some_arg
98
+ end
99
+
100
+ include EasyCallbacks::Base
101
+
102
+ # ...
103
+
104
+ end
105
+
106
+ end
107
+
108
+ SomeClass.some_method 'some arg'
109
+
110
+ == Changelog
111
+
112
+ See 'changelog.txt' to follow the progress.
113
+
87
114
  ===
88
115
 
89
116
  {<img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" alt="Donate" />}[https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9KHDLTWYK9A62]
data/changelog.txt ADDED
@@ -0,0 +1,4 @@
1
+ # 0.1.0
2
+
3
+ - adding 'object' key to 'callback_details' providing context to anonymous callbacks
4
+ - removing 'method_missing' strategy from base module, this isn't strictly necessary
@@ -7,25 +7,25 @@ module EasyCallbacks
7
7
 
8
8
  include MethodDecorator
9
9
 
10
- TYPES = %w(before around after)
11
-
12
10
  class << self
13
11
 
14
12
  attr_accessor :callbacks
15
13
 
16
- def method_missing(method_sym, *args, &block)
17
- if TYPES.include? method_sym.to_s
18
- target = args.first
19
- callback_name = args.count.eql?(1) ? nil : args.last
20
- handle_method_missing method_sym, target, callback_name, &block
21
- else
22
- super method_sym, *args, &block
23
- end
14
+ def before(target, callback_name=nil, &block)
15
+ handle_callback_definition :before, target, callback_name, &block
16
+ end
17
+
18
+ def around(target, callback_name=nil, &block)
19
+ handle_callback_definition :around, target, callback_name, &block
20
+ end
21
+
22
+ def after(target, callback_name=nil, &block)
23
+ handle_callback_definition :after, target, callback_name, &block
24
24
  end
25
25
 
26
26
  private
27
27
 
28
- def handle_method_missing(type, target, callback_name, &block)
28
+ def handle_callback_definition(type, target, callback_name, &block)
29
29
  push_callback type, target, callback_name, &block
30
30
  decorate_target target
31
31
  end
@@ -61,10 +61,6 @@ module EasyCallbacks
61
61
  end unless method_defined? original_method_name_for(target)
62
62
  end
63
63
 
64
- def respond_to_missing?(target, include_private=false)
65
- TYPES.include?(target) ? true : super ;
66
- end
67
-
68
64
  end
69
65
 
70
66
  def execute_callbacks_for(type, target, additional_options, *args, &block)
@@ -82,7 +78,12 @@ module EasyCallbacks
82
78
 
83
79
  arguments.last.merge! additional_options if additional_options
84
80
 
85
- proc.nil? ? send(cn, *arguments, &block) : proc.call(*arguments, &block)
81
+ if proc.nil?
82
+ send(cn, *arguments, &block)
83
+ else
84
+ arguments.last.merge! object: self
85
+ proc.nil? ? send(cn, *arguments, &block) : proc.call(*arguments, &block)
86
+ end
86
87
  end
87
88
  end
88
89
 
@@ -1,3 +1,3 @@
1
1
  module EasyCallbacks
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_callbacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - r4z3c
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-19 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,6 +107,7 @@ files:
107
107
  - MIT-LICENSE
108
108
  - README.rdoc
109
109
  - Rakefile
110
+ - changelog.txt
110
111
  - easy_callbacks.gemspec
111
112
  - lib/easy_callbacks.rb
112
113
  - lib/easy_callbacks/base.rb