dumb_delegator 0.6.0 → 0.7.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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +5 -3
- data/Rakefile +2 -2
- data/lib/dumb_delegator.rb +3 -2
- data/lib/dumb_delegator/version.rb +1 -1
- data/spec/dumb_delegator_spec.rb +37 -30
- data/spec/spec_helper.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cae66a8a74772ba193dd066ab5b030b6cc9ab526
|
4
|
+
data.tar.gz: dfa72a06e4197d605dcd0dbb3d4865c92d9b2d61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8df3f3d465f33af6d63aa2f9444effa6dbcdbc22e8b1d7b6062030ba3ea5921618602e8bc6d69fcecd7b9fc53d45e0e5b691a95a8342dbb452ab5946fda4826f
|
7
|
+
data.tar.gz: 93dd9e69cd72bd079f84070eba0f077c267f3432e0566b3d6135cb911a0142a0b858b15717edc4578db1d63dad13dc6be6dbaa11d9089fa75aeb3517ccff2a0f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# DumbDelegator
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/dumb_delegator)
|
4
|
+
[](https://travis-ci.org/stevenharman/dumb_delegator)
|
5
|
+
[](https://codeclimate.com/github/stevenharman/dumb_delegator)
|
6
|
+
[](https://gemnasium.com/stevenharman/dumb_delegator)
|
5
7
|
|
6
8
|
Ruby provides the `delegate` standard library. However, we found that it is not
|
7
9
|
appropriate for many use cases that require nearly every call to be proxied.
|
@@ -62,7 +64,7 @@ class Coffee
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def origin
|
65
|
-
|
67
|
+
'Colombia'
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
6
|
-
t.rspec_opts =
|
6
|
+
t.rspec_opts = '--tag ~objectspace' if RUBY_PLATFORM == 'java'
|
7
7
|
end
|
8
8
|
|
9
9
|
task :default => :spec
|
data/lib/dumb_delegator.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'set'
|
2
|
+
require 'dumb_delegator/version'
|
3
3
|
|
4
4
|
class DumbDelegator < ::BasicObject
|
5
5
|
(::BasicObject.instance_methods - [:equal?, :__id__, :__send__, :method_missing]).each do |method|
|
@@ -33,6 +33,7 @@ class DumbDelegator < ::BasicObject
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def __setobj__(obj)
|
36
|
+
raise ::ArgumentError, 'Delegation to self is not allowed.' if obj.__id__ == __id__
|
36
37
|
@__dumb_target__ = obj
|
37
38
|
end
|
38
39
|
|
data/spec/dumb_delegator_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DumbDelegator do
|
4
4
|
subject(:dummy) { described_class.new(target) }
|
5
5
|
let(:target) { double }
|
6
6
|
|
7
|
-
it
|
7
|
+
it 'delegates to the target object' do
|
8
8
|
expect(target).to receive(:foo)
|
9
9
|
dummy.foo
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'delegates to the target object with arguments' do
|
13
13
|
expect(target).to receive(:foo).with(:bar)
|
14
14
|
|
15
15
|
dummy.foo(:bar)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
bar_block = proc {
|
18
|
+
it 'delegates to the target object with a block' do
|
19
|
+
bar_block = proc { 'bar' }
|
20
20
|
expect(target).to receive(:foo) { |&block| expect(block).to eq(bar_block) }
|
21
21
|
|
22
22
|
dummy.foo(&bar_block)
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'does not delegate if the target does not respond_to? the message' do
|
26
26
|
allow(target).to receive(:foo)
|
27
27
|
allow(target).to receive(:respond_to?).with(:foo).and_return(false)
|
28
28
|
|
@@ -31,80 +31,80 @@ describe DumbDelegator do
|
|
31
31
|
}.to raise_error(NoMethodError)
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'responds to methods defined by child classes that add behavior' do
|
35
35
|
expect(target).to receive(:foo).never
|
36
36
|
def dummy.foo
|
37
|
-
|
37
|
+
'bar'
|
38
38
|
end
|
39
39
|
|
40
40
|
dummy.foo
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'delegates methods defined on Object' do
|
44
44
|
expect(target).to receive(:class)
|
45
45
|
dummy.class
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'delegates is_a?' do
|
49
49
|
expect(target).to receive(:is_a?)
|
50
50
|
dummy.is_a?
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'delegates methods defined on Kernel' do
|
54
54
|
expect(target).to receive(:print)
|
55
55
|
dummy.print
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it 'delegates !' do
|
59
59
|
expect(target).to receive(:!)
|
60
60
|
!dummy
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'delegates !=' do
|
64
64
|
expect(target).to receive(:!=)
|
65
65
|
dummy != 1
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it 'delegates ==' do
|
69
69
|
expect(target).to receive(:==)
|
70
70
|
dummy == 1
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'delegates ==' do
|
74
74
|
expect(target).to receive(:==)
|
75
75
|
dummy == 1
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
78
|
+
it 'delegates instance_eval' do
|
79
79
|
expect(target).to receive(:instance_eval)
|
80
80
|
dummy.instance_eval { true }
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it 'delegates instance_exec' do
|
84
84
|
expect(target).to receive(:instance_exec)
|
85
85
|
dummy.instance_exec { true }
|
86
86
|
end
|
87
87
|
|
88
|
-
describe
|
89
|
-
it
|
88
|
+
describe '#dup' do
|
89
|
+
it 'returns a shallow of itself, the delegator (not the underlying object)', :objectspace => true do
|
90
90
|
dupped = dummy.dup
|
91
91
|
|
92
92
|
expect(ObjectSpace.each_object(DumbDelegator).map(&:__id__)).to include dupped.__id__
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
97
|
-
it
|
96
|
+
describe '#clone' do
|
97
|
+
it 'returns a shallow of itself, the delegator (not the underlying object)', :objectspace => true do
|
98
98
|
cloned = dummy.clone
|
99
99
|
|
100
100
|
expect(ObjectSpace.each_object(DumbDelegator).map(&:__id__)).to include cloned.__id__
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe
|
104
|
+
describe 'marshaling' do
|
105
105
|
let(:target) { Object.new }
|
106
106
|
|
107
|
-
it
|
107
|
+
it 'marshals and unmarshals itself, the delegator (not the underlying object)', :objectspace => true do
|
108
108
|
marshaled = Marshal.dump(dummy)
|
109
109
|
unmarshaled = Marshal.load(marshaled)
|
110
110
|
|
@@ -112,30 +112,30 @@ describe DumbDelegator do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe
|
115
|
+
describe '#respond_to?' do
|
116
116
|
[:equal?, :__id__, :__send__, :dup, :clone, :__getobj__, :__setobj__, :marshal_dump, :marshal_load, :respond_to?].each do |method|
|
117
117
|
it "responds to #{method}" do
|
118
118
|
expect(dummy.respond_to?(method)).to be_true
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
context
|
122
|
+
context 'subclasses of DumbDelegator' do
|
123
123
|
subject(:dummy) { Class.new(DumbDelegator) { def foobar; end }.new([]) }
|
124
124
|
|
125
|
-
it
|
125
|
+
it 'respond to methods defined on the subclass' do
|
126
126
|
expect(dummy.respond_to?(:foobar)).to be_true
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
describe
|
132
|
-
it
|
131
|
+
describe '#__getobj__' do
|
132
|
+
it 'returns the target object' do
|
133
133
|
expect(dummy.__getobj__).to equal target
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
describe
|
138
|
-
it
|
137
|
+
describe '#__setobj__' do
|
138
|
+
it 'resets the target object to a different object' do
|
139
139
|
expect(target).to receive(:foo).never
|
140
140
|
|
141
141
|
new_target = double
|
@@ -144,5 +144,12 @@ describe DumbDelegator do
|
|
144
144
|
dummy.__setobj__(new_target)
|
145
145
|
dummy.foo
|
146
146
|
end
|
147
|
+
|
148
|
+
it 'cannot delegate to itself' do
|
149
|
+
expect {
|
150
|
+
dummy.__setobj__(dummy)
|
151
|
+
dummy.foo
|
152
|
+
}.to raise_error(ArgumentError, 'Delegation to self is not allowed.')
|
153
|
+
end
|
147
154
|
end
|
148
155
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
2
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
# Require this file using `require
|
3
|
+
# Require this file using `require 'spec_helper.rb'` to ensure that it is only
|
4
4
|
# loaded once.
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dumb_delegator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Lindeman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -101,3 +101,4 @@ summary: Delegator and SimpleDelegator in Ruby's stdlib are somewhat useful, but
|
|
101
101
|
test_files:
|
102
102
|
- spec/dumb_delegator_spec.rb
|
103
103
|
- spec/spec_helper.rb
|
104
|
+
has_rdoc:
|