method_man 2.1.2 → 2.1.3

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: 4003ab3ee51fcd4973bbf6766b5a8aff6505ce8d
4
- data.tar.gz: 22ca0e3e65ebe890bcafdeaa5aa2c1484370cb14
3
+ metadata.gz: 4fdbcefd427794328ed76138ee1ae3c40652be07
4
+ data.tar.gz: f7a19bd8d6a86ff56c293e31eaa80e0696139b86
5
5
  SHA512:
6
- metadata.gz: b9a6c8903baf7d83cdf0d46211241a38dd16643690baf27371bcc62a72fea11d3852c28ab3b642d893416603d805267e41ff06824c3b1f3d7dd8c75828606bcf
7
- data.tar.gz: b44775573ba4c9e40d2f6080926c183a2398439d95a25dda82d57c492f7b0e12870c6bc97f306bc47f88020e81f30f4abf30645465d06d7445504265d570d44d
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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'https://rubygems.org'
3
4
 
4
5
  # Specify your gem's dependencies in method_man.gemspec
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'bundler/gem_tasks'
data/lib/method_object.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'method_object/version'
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
- define_and_call_new_method(candidates.first)
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 define_and_call_new_method(candidate)
67
+ def define_delegated_method(delegate)
65
68
  self.class.class_eval(
66
69
  <<-RUBY
67
- def #{candidate.delegated_method}
68
- #{candidate.attribute}.#{candidate.method_to_call_on_delegate}
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)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class MethodObject
3
- VERSION = '2.1.2'
4
+ VERSION = '2.1.3'
4
5
  end
data/method_man.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  lib = File.expand_path('../lib', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require 'method_object/version'
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'method_object'
3
2
 
4
- describe MethodObject do
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
- def self.sent_messages
152
- @sent_messages
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.2
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-03-15 00:00:00.000000000 Z
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.8
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"