hanging_methods 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd6aa759c5ca36bb17d4fc8e64ccda3157e2209a
4
+ data.tar.gz: 369a4767b84b7d263db0c178290effb944326660
5
+ SHA512:
6
+ metadata.gz: cfe4311ff4057781f7e91e6cf5bad998c9b4c46f09f85165e42c0acd70fcd087956fe2a6636711b15878a6ab6998fc9948071f4b11afb901c13cb65e33a877d6
7
+ data.tar.gz: 3ba97f154b64037749db7aa8e337e0e796dce8e3dca2956e3ef7b2c79df7805e7db5fb48b0f275742c41a5a35845d611a692fa4a789cb2906b6e92a51ac6ae05
data/README.md CHANGED
@@ -14,12 +14,11 @@ See [Parallizer](https://github.com/michaelgpearce/parallizer) for an example.
14
14
  Here's an example.
15
15
 
16
16
  ```ruby
17
- require 'rubygems'
18
17
  require 'hanging_methods'
19
18
 
20
19
  class Interesting
21
20
  include HangingMethods
22
-
21
+
23
22
  add_hanging_method :add
24
23
  end
25
24
 
@@ -37,25 +36,23 @@ puts interesting.hanging_method_invocations(:add)
37
36
  You can be notified of method being hanged and specify its result.
38
37
 
39
38
  ```ruby
40
- require 'rubygems'
41
39
  require 'hanging_methods'
42
40
 
43
41
  class Interesting
44
42
  include HangingMethods
45
-
43
+
46
44
  add_hanging_method :add, after_invocation: :added
47
45
 
48
46
  private
49
47
 
50
- def added(method_name_and_arguments)
51
- # method_name_and_arguments is [:a_method, 1, 2]
52
- return :very_interesting
48
+ def added(method_name, arg_1, arg_2, &block)
49
+ return "very_interesting: #{arg_1}, #{arg_2}, #{yield}"
53
50
  end
54
51
  end
55
52
 
56
53
  interesting = Interesting.new
57
- interesting.add.a_method(1, 2)
58
- # returns :very_interesting
54
+ interesting.add.a_method(1, 2) { 3 }
55
+ # returns "very_interesting: 1, 2, 3"
59
56
  ```
60
57
 
61
58
  # Credits
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_development_dependency 'rake'
23
- s.add_development_dependency 'rspec', '~> 2.14.0'
22
+ s.add_development_dependency 'rake', '~> 0', '>= 0'
23
+ s.add_development_dependency 'rspec', '~> 2.14.0', '>= 2.14.0'
24
24
  end
@@ -6,41 +6,47 @@ module HangingMethods
6
6
  def add_hanging_method(hanging_method_name, options = {})
7
7
  unknown_keys = options.keys - [:after_invocation]
8
8
  raise ArgumentError, "Unknown keys: #{unknown_keys.join(',')}" unless unknown_keys.empty?
9
-
9
+
10
10
  add_hanging_method_options(hanging_method_name, options)
11
-
11
+
12
12
  define_method(hanging_method_name) do
13
- ::HangingMethods::MethodCallNotifier.new do |*method_name_and_args|
14
- add_hanging_method_name_and_args_invocation(hanging_method_name, method_name_and_args)
13
+ ::HangingMethods::MethodCallNotifier.new do |*method_name_and_args, &block|
14
+ add_hanging_method_invocation(hanging_method_name, method_name_and_args, block)
15
15
  end
16
16
  end
17
17
  end
18
-
18
+
19
19
  def add_hanging_method_options(hanging_method_name, options)
20
20
  hanging_method_options(hanging_method_name).merge!(options)
21
21
  end
22
-
22
+
23
23
  def hanging_method_options(hanging_method_name)
24
24
  @hanging_method_options ||= {}
25
25
  @hanging_method_options[hanging_method_name] ||= {}
26
26
  end
27
27
  end
28
-
28
+
29
29
  module InstanceMethods
30
- def add_hanging_method_name_and_args_invocation(hanging_method_name, method_name_and_args)
30
+ def add_hanging_method_invocation(hanging_method_name, method_name_and_args, block)
31
31
  hanging_method_invocations(hanging_method_name) << method_name_and_args
32
-
32
+ hanging_method_blocks(hanging_method_name) << block
33
+
33
34
  ret = if after_invocation = self.method(hanging_method_name).owner.hanging_method_options(hanging_method_name)[:after_invocation]
34
- send(after_invocation, method_name_and_args)
35
+ send(after_invocation, method_name_and_args[0], *method_name_and_args[1..-1], &block)
35
36
  end
36
37
  end
37
-
38
+
38
39
  def hanging_method_invocations(hanging_method_name)
39
40
  @hanging_method_invocations ||= {}
40
41
  @hanging_method_invocations[hanging_method_name] ||= []
41
42
  end
43
+
44
+ def hanging_method_blocks(hanging_method_name)
45
+ @hanging_method_blocks ||= {}
46
+ @hanging_method_blocks[hanging_method_name] ||= []
47
+ end
42
48
  end
43
-
49
+
44
50
  def self.included(base)
45
51
  base.send(:include, InstanceMethods)
46
52
  base.send(:extend, ClassMethods)
@@ -3,9 +3,9 @@ module HangingMethods
3
3
  def initialize(&callback)
4
4
  @callback = callback
5
5
  end
6
-
6
+
7
7
  def method_missing(name, *arguments, &block)
8
- @callback.call(name, *arguments)
8
+ @callback.call(name, *arguments, &block)
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module HangingMethods
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,46 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanging_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Pearce
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ - - ">="
20
21
  - !ruby/object:Gem::Version
21
22
  version: '0'
22
23
  type: :development
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - - ">="
28
31
  - !ruby/object:Gem::Version
29
32
  version: '0'
30
33
  - !ruby/object:Gem::Dependency
31
34
  name: rspec
32
35
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
36
  requirements:
35
- - - ~>
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.14.0
40
+ - - ">="
36
41
  - !ruby/object:Gem::Version
37
42
  version: 2.14.0
38
43
  type: :development
39
44
  prerelease: false
40
45
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
46
  requirements:
43
- - - ~>
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 2.14.0
50
+ - - ">="
44
51
  - !ruby/object:Gem::Version
45
52
  version: 2.14.0
46
53
  description: Add a method that you can hang other methods.
@@ -50,7 +57,7 @@ executables: []
50
57
  extensions: []
51
58
  extra_rdoc_files: []
52
59
  files:
53
- - .gitignore
60
+ - ".gitignore"
54
61
  - Gemfile
55
62
  - Gemfile.lock
56
63
  - LICENSE.txt
@@ -66,27 +73,26 @@ files:
66
73
  homepage: http://github.com/michaelgpearce/hanging_methods
67
74
  licenses:
68
75
  - MIT
76
+ metadata: {}
69
77
  post_install_message:
70
78
  rdoc_options: []
71
79
  require_paths:
72
80
  - lib
73
81
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
82
  requirements:
76
- - - ! '>='
83
+ - - ">="
77
84
  - !ruby/object:Gem::Version
78
85
  version: '0'
79
86
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
87
  requirements:
82
- - - ! '>='
88
+ - - ">="
83
89
  - !ruby/object:Gem::Version
84
90
  version: '0'
85
91
  requirements: []
86
92
  rubyforge_project: hanging_methods
87
- rubygems_version: 1.8.25
93
+ rubygems_version: 2.4.8
88
94
  signing_key:
89
- specification_version: 3
95
+ specification_version: 4
90
96
  summary: Add a method that you can hang other methods
91
97
  test_files:
92
98
  - spec/hanging_methods/method_call_notifier_spec.rb