method_man 2.1.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -3
- data/Gemfile +1 -0
- data/Rakefile +1 -0
- data/lib/method_object.rb +9 -6
- data/lib/method_object/version.rb +2 -1
- data/method_man.gemspec +1 -0
- data/spec/method_man_spec.rb +15 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fdbcefd427794328ed76138ee1ae3c40652be07
|
4
|
+
data.tar.gz: f7a19bd8d6a86ff56c293e31eaa80e0696139b86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a12a8183393dc8401035a3f8d0da9c3f5a45d1d0ac5a525198e5130c7c0af0b644ba47091c4654a7d9fa027195a339f195a883f951fb6464a76990cb7cdab9b
|
7
|
+
data.tar.gz: 98b2d6d7287be407b4a27c910b20527426167415ad91d4b1daff6916986c5f2c1a3286fbd4d89e2ee8d2a50d04e30143ff7b3e8c919ae844b96b1a67840035fd
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## 2.1.1
|
4
|
+
Fix bug preventing arguments from being forwarded to delegated methods.
|
5
|
+
|
6
|
+
## 2.1.0
|
7
|
+
Allow automatic delegation inspired by Golang's embedding.
|
8
|
+
|
3
9
|
## 2.0.0
|
4
10
|
Convert MethodObject to use inheritance and a class method for dynamic setup of class internals
|
5
11
|
- Enables code editors to find declaration of MethodObject
|
6
12
|
- Allows constants to be nested whereas previous implementation was based on a Struct which could not contain constants.
|
7
|
-
|
8
|
-
## 2.1.0
|
9
|
-
Allow automatic delegation inspired by Golang's embedding.
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/method_object.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require('method_object/version')
|
3
4
|
|
4
5
|
# See gemspec for description
|
5
6
|
class MethodObject
|
@@ -32,7 +33,9 @@ class MethodObject
|
|
32
33
|
when 0
|
33
34
|
super
|
34
35
|
when 1
|
35
|
-
|
36
|
+
delegate = candidates.first
|
37
|
+
define_delegated_method(delegate)
|
38
|
+
public_send(delegate.delegated_method, *args, &block)
|
36
39
|
else
|
37
40
|
handle_ambiguous_missing_method(candidates, name)
|
38
41
|
end
|
@@ -61,15 +64,15 @@ class MethodObject
|
|
61
64
|
potential_candidates.select(&:candidate?)
|
62
65
|
end
|
63
66
|
|
64
|
-
def
|
67
|
+
def define_delegated_method(delegate)
|
65
68
|
self.class.class_eval(
|
66
69
|
<<-RUBY
|
67
|
-
def #{
|
68
|
-
#{
|
70
|
+
def #{delegate.delegated_method}(*args, &block)
|
71
|
+
#{delegate.attribute}
|
72
|
+
.#{delegate.method_to_call_on_delegate}(*args, &block)
|
69
73
|
end
|
70
74
|
RUBY
|
71
75
|
)
|
72
|
-
public_send(candidate.delegated_method)
|
73
76
|
end
|
74
77
|
|
75
78
|
def handle_ambiguous_missing_method(candidates, method_name)
|
data/method_man.gemspec
CHANGED
data/spec/method_man_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'method_object'
|
3
2
|
|
4
|
-
|
3
|
+
require('method_object')
|
4
|
+
|
5
|
+
RSpec.describe(MethodObject) do
|
5
6
|
it 'makes new a private class method' do
|
6
7
|
expect { subject.new }.to raise_error(NoMethodError)
|
7
8
|
end
|
@@ -23,17 +24,13 @@ describe MethodObject do
|
|
23
24
|
Class.new(described_class) do
|
24
25
|
attrs(:company, :user)
|
25
26
|
|
26
|
-
@sent_messages = []
|
27
|
-
|
28
|
-
def self.sent_messages
|
29
|
-
@sent_messages
|
30
|
-
end
|
31
|
-
|
32
27
|
def call
|
33
28
|
{
|
34
29
|
address: address,
|
35
30
|
respond_to_address: respond_to_missing?(:address),
|
36
31
|
company_address: company_address,
|
32
|
+
id_for_joe: company_id_for('Joe'),
|
33
|
+
block_arg: company_run_a_block { |block_arg| block_arg * 2 },
|
37
34
|
respond_to_company_address: respond_to_missing?(:company_address),
|
38
35
|
company: company,
|
39
36
|
respond_to_name: respond_to_missing?(:name),
|
@@ -50,6 +47,12 @@ describe MethodObject do
|
|
50
47
|
|
51
48
|
let(:company) do
|
52
49
|
double('company', address: company_address, name: company_name)
|
50
|
+
.tap do |company|
|
51
|
+
allow(company).to receive(:id_for).with('Joe').and_return(1234)
|
52
|
+
allow(company).to receive(:run_a_block) do |&block|
|
53
|
+
block.call(4321)
|
54
|
+
end
|
55
|
+
end
|
53
56
|
end
|
54
57
|
let(:company_address) { '101 Minitru Lane' }
|
55
58
|
let(:company_name) { 'Periscope Data' }
|
@@ -63,6 +66,8 @@ describe MethodObject do
|
|
63
66
|
address: company_address,
|
64
67
|
respond_to_address: true,
|
65
68
|
company_address: company_address,
|
69
|
+
id_for_joe: 1234,
|
70
|
+
block_arg: 8642,
|
66
71
|
respond_to_company_address: true,
|
67
72
|
company: company,
|
68
73
|
respond_to_name: false,
|
@@ -148,8 +153,8 @@ describe MethodObject do
|
|
148
153
|
attrs(:company)
|
149
154
|
@sent_messages = []
|
150
155
|
|
151
|
-
|
152
|
-
|
156
|
+
class << self
|
157
|
+
attr_reader(:sent_messages)
|
153
158
|
end
|
154
159
|
|
155
160
|
def call
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clay Shentrup
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.6.
|
98
|
+
rubygems_version: 2.6.11
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Provides a MethodObject class which implements KentBeck's "method object"
|