dumb_delegator 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92d88fb2dc6ea85760c5b7d646349b40bca6dbfe
4
- data.tar.gz: e457fa632733529197f767f6fc798e35d57db3fe
3
+ metadata.gz: cae66a8a74772ba193dd066ab5b030b6cc9ab526
4
+ data.tar.gz: dfa72a06e4197d605dcd0dbb3d4865c92d9b2d61
5
5
  SHA512:
6
- metadata.gz: 6ca10a81f035210ac1b7b45b579e765af3baa14c2c9fa349814fac4aea22bc1a008d888145bef02f53048fbe9bdf43da4b8eb5db9d8f9c002e4d5705c3eba976
7
- data.tar.gz: a641af0af00a6999fa5d3f5484a742db80d23c47e7b31475673ec66080219f4d0b127158fdbd434f4e16b042f7ff848528358c470e760c93543ef7830ef111a2
6
+ metadata.gz: 8df3f3d465f33af6d63aa2f9444effa6dbcdbc22e8b1d7b6062030ba3ea5921618602e8bc6d69fcecd7b9fc53d45e0e5b691a95a8342dbb452ab5946fda4826f
7
+ data.tar.gz: 93dd9e69cd72bd079f84070eba0f077c267f3432e0566b3d6135cb911a0142a0b858b15717edc4578db1d63dad13dc6be6dbaa11d9089fa75aeb3517ccff2a0f
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .ruby-version
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/.travis.yml CHANGED
@@ -4,5 +4,6 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.0
7
+ - 2.1.1
7
8
  - jruby-19mode
8
9
  - rbx
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # DumbDelegator
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/stevenharman/dumb_delegator.png)](http://travis-ci.org/stevenharman/dumb_delegator)
4
- [![Dependency Status](https://gemnasium.com/stevenharman/dumb_delegator.png)](https://gemnasium.com/stevenharman/dumb_delegator)
3
+ [![Gem Version](http://img.shields.io/gem/v/dumb_delegator.svg)](https://rubygems.org/gems/dumb_delegator)
4
+ [![Build Status](https://img.shields.io/travis/stevenharman/dumb_delegator.svg)](https://travis-ci.org/stevenharman/dumb_delegator)
5
+ [![Code Climate](http://img.shields.io/codeclimate/github/stevenharman/dumb_delegator.svg)](https://codeclimate.com/github/stevenharman/dumb_delegator)
6
+ [![Dependency Status](https://img.shields.io/gemnasium/stevenharman/dumb_delegator.svg)](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
- "Colombia"
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 "bundler/gem_tasks"
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 = "--tag ~objectspace" if RUBY_PLATFORM == "java"
6
+ t.rspec_opts = '--tag ~objectspace' if RUBY_PLATFORM == 'java'
7
7
  end
8
8
 
9
9
  task :default => :spec
@@ -1,5 +1,5 @@
1
- require "set"
2
- require "dumb_delegator/version"
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
 
@@ -1,3 +1,3 @@
1
1
  class DumbDelegator < ::BasicObject
2
- VERSION = "0.6.0"
2
+ VERSION = '0.7.0'
3
3
  end
@@ -1,28 +1,28 @@
1
- require "spec_helper"
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 "delegates to the target object" do
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 "delegates to the target object with arguments" do
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 "delegates to the target object with a block" do
19
- bar_block = proc { "bar" }
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 "does not delegate if the target does not respond_to? the message" do
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 "responds to methods defined by child classes that add behavior" do
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
- "bar"
37
+ 'bar'
38
38
  end
39
39
 
40
40
  dummy.foo
41
41
  end
42
42
 
43
- it "delegates methods defined on Object" do
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 "delegates is_a?" do
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 "delegates methods defined on Kernel" do
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 "delegates !" do
58
+ it 'delegates !' do
59
59
  expect(target).to receive(:!)
60
60
  !dummy
61
61
  end
62
62
 
63
- it "delegates !=" do
63
+ it 'delegates !=' do
64
64
  expect(target).to receive(:!=)
65
65
  dummy != 1
66
66
  end
67
67
 
68
- it "delegates ==" do
68
+ it 'delegates ==' do
69
69
  expect(target).to receive(:==)
70
70
  dummy == 1
71
71
  end
72
72
 
73
- it "delegates ==" do
73
+ it 'delegates ==' do
74
74
  expect(target).to receive(:==)
75
75
  dummy == 1
76
76
  end
77
77
 
78
- it "delegates instance_eval" do
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 "delegates instance_exec" do
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 "#dup" do
89
- it "returns a shallow of itself, the delegator (not the underlying object)", :objectspace => true do
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 "#clone" do
97
- it "returns a shallow of itself, the delegator (not the underlying object)", :objectspace => true do
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 "marshaling" do
104
+ describe 'marshaling' do
105
105
  let(:target) { Object.new }
106
106
 
107
- it "marshals and unmarshals itself, the delegator (not the underlying object)", :objectspace => true do
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 "#respond_to?" do
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 "subclasses of DumbDelegator" do
122
+ context 'subclasses of DumbDelegator' do
123
123
  subject(:dummy) { Class.new(DumbDelegator) { def foobar; end }.new([]) }
124
124
 
125
- it "respond to methods defined on the subclass" do
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 "#__getobj__" do
132
- it "returns the target object" do
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 "#__setobj__" do
138
- it "resets the target object to a different object" do
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 "spec_helper.rb"` to ensure that it is only
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.6.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-10 00:00:00.000000000 Z
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: