dumb_delegator 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: 3dfd1848821cd96312119f18cd2cc09bfcdc72c2efca3f53ddca59bb6247008f
4
- data.tar.gz: 6dfd0d7689ed6b8d83dd0029e3687e624594e021c5ed0c58ca4ce6489abd8812
3
+ metadata.gz: aad024505a2fc9c628c3bee2cd7a7e5e769c1b18142a0e27da056106e53c86bb
4
+ data.tar.gz: d4110bc2ebe767e3a6a189345926a50c5d0b322a3ff9e0bcc3aef35b2d16a0ec
5
5
  SHA512:
6
- metadata.gz: 72c45104a5258f109d258c6ff3268da7b7f1d2810f4a22ee916f8806d8cd5f3ca76ef01cfa6a7d2e18347158a25b4a727814e49be8ddec576a40d3b2bee6ca61
7
- data.tar.gz: 49588ab5d55d168cf1916c7961285e9dc1c1a2f8fe0a6a097e6c671adee01424e374e99797410018e891fc6c9e09069515efbb84331fbd2f4c1cf9b486229ecd
6
+ metadata.gz: 76f2e43119fbb66b69a580466241531ca39c54008b633b80eb8aab5ab2c7842508e85a9a8075d98b792bb46269f56cc37b093df4f414e1c010a5e74d59bd2904
7
+ data.tar.gz: 77d79fa8490019da9bef17e22f745a6535111c4f07331d2d77a8396be5371bfbe4afa6eb73689dddcdc9c42a725f9bf99e969dcac066921d437c06633f6ef3ea
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.1.0] 2024-12-17
9
+ ### Changed
10
+ - Use `__getobj__` to be compatible with the `Delegator` "interface." [@cervantn [14](https://github.com/stevenharman/dumb_delegator/pull/14)]
11
+
8
12
  ## [1.0.0] 2020-01-27
9
13
  ### Changed
10
14
  - Require Ruby >= 2.4. We may still work with older Rubies, but no promises.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # DumbDelegator
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/dumb_delegator.svg)](https://badge.fury.io/rb/dumb_delegator)
4
- [![Build Status](https://travis-ci.org/stevenharman/dumb_delegator.svg?branch=master)](https://travis-ci.org/stevenharman/dumb_delegator)
3
+ [![Gem Version](https://badge.fury.io/rb/dumb_delegator.svg?icon=si%3Arubygems&icon_color=%23ff2600)](https://badge.fury.io/rb/dumb_delegator)
4
+ [![CI](https://github.com/stevenharman/dumb_delegator/actions/workflows/ci.yml/badge.svg)](https://github.com/stevenharman/dumb_delegator/actions/workflows/ci.yml)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/b684cbe08af745cbe957/maintainability)](https://codeclimate.com/github/stevenharman/dumb_delegator/maintainability)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/b684cbe08af745cbe957/test_coverage)](https://codeclimate.com/github/stevenharman/dumb_delegator/test_coverage)
7
7
 
@@ -43,19 +43,19 @@ d.is_a? MyAwesomeClass #=> true
43
43
 
44
44
  ## Installation
45
45
 
46
- Add this line to your application's Gemfile:
46
+ Add this line to your Gemfile:
47
47
 
48
48
  ```ruby
49
49
  gem "dumb_delegator"
50
50
  ```
51
51
 
52
- And then execute:
52
+ And then install:
53
53
 
54
54
  ```bash
55
55
  $ bundle
56
56
  ```
57
57
 
58
- Or install it yourself as:
58
+ Or install it yourself:
59
59
 
60
60
  ```bash
61
61
  $ gem install dumb_delegator
@@ -68,9 +68,9 @@ This project adheres to [Semantic Versioning][semver].
68
68
  #### Version `0.8.x`
69
69
 
70
70
  The `0.8.0` release was downloaded 1.2MM times before the `1.0.0` work began.
71
- Which is great.
71
+ Which is great! 🎉
72
72
  But, we wanted to clean up some cruft, fix a few small things, and improve ergonomics.
73
- And do all of that, while, hopefully, not breaking existing usage.
73
+ And we wanted to do all of that while, hopefully, not breaking existing usage.
74
74
 
75
75
  To that end, `1.0.0` dropped support for all [EoL'd Rubies][ruby-releases] and only officially supported Ruby `2.4` - `2.7` when it was released.
76
76
  However, most older Rubies, _should_ still work.
@@ -81,7 +81,7 @@ If you're on an EoL'd Ruby, please try the `0.8.x` versions of this gem.
81
81
  ## Usage
82
82
 
83
83
  `DumbDelegator`'s API and usage patters were inspired by Ruby stdlib's `SimpleDelegator`.
84
- As such, the usage and ergonomics are quite similar.
84
+ So the usage and ergonomics are quite similar.
85
85
 
86
86
  ```ruby
87
87
  require "dumb_delegator"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DumbDelegator < ::BasicObject
2
4
  ##
3
5
  # This optional extension enables a Class/Module to support +case+ statements.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DumbDelegator < ::BasicObject
2
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "dumb_delegator/triple_equal_ext"
2
4
  require "dumb_delegator/version"
3
5
 
@@ -59,8 +61,8 @@ class DumbDelegator < ::BasicObject
59
61
  end
60
62
 
61
63
  def method_missing(method, *args, &block)
62
- if @__dumb_target__.respond_to?(method)
63
- @__dumb_target__.__send__(method, *args, &block)
64
+ if __getobj__.respond_to?(method)
65
+ __getobj__.__send__(method, *args, &block)
64
66
  else
65
67
  super
66
68
  end
@@ -84,7 +86,7 @@ class DumbDelegator < ::BasicObject
84
86
  def marshal_dump
85
87
  [
86
88
  :__v1__,
87
- __getobj__,
89
+ __getobj__
88
90
  ]
89
91
  end
90
92
 
metadata CHANGED
@@ -1,58 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumb_delegator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Lindeman
8
8
  - Steven Harman
9
- autorequire:
10
- bindir: bin
9
+ autorequire:
10
+ bindir: exe
11
11
  cert_chain: []
12
- date: 2020-01-28 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: pry
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '13.0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '13.0'
42
- - !ruby/object:Gem::Dependency
43
- name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '3.9'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '3.9'
12
+ date: 2024-12-17 00:00:00.000000000 Z
13
+ dependencies: []
56
14
  description: |
57
15
  Delegator and SimpleDelegator in Ruby's stdlib are useful, but they pull in most of Kernel.
58
16
  This is not appropriate for many uses; for instance, delegation to Rails Models.
@@ -64,28 +22,23 @@ executables: []
64
22
  extensions: []
65
23
  extra_rdoc_files: []
66
24
  files:
67
- - ".gitignore"
68
25
  - ".rspec"
69
- - ".travis.yml"
70
26
  - CHANGELOG.md
71
- - Gemfile
72
27
  - LICENSE
73
28
  - README.md
74
29
  - Rakefile
75
- - dumb_delegator.gemspec
76
30
  - lib/dumb_delegator.rb
77
31
  - lib/dumb_delegator/triple_equal_ext.rb
78
32
  - lib/dumb_delegator/version.rb
79
- - spec/dumb_delegator_spec.rb
80
- - spec/spec_helper.rb
81
33
  homepage: https://github.com/stevenharman/dumb_delegator
82
34
  licenses:
83
35
  - MIT
84
36
  metadata:
85
37
  changelog_uri: https://github.com/stevenharman/dumb_delegator/blob/master/CHANGELOG.md
86
38
  documentation_uri: https://rubydoc.info/gems/dumb_delegator
39
+ homepage_uri: https://github.com/stevenharman/dumb_delegator
87
40
  source_code_uri: https://github.com/stevenharman/dumb_delegator
88
- post_install_message:
41
+ post_install_message:
89
42
  rdoc_options: []
90
43
  require_paths:
91
44
  - lib
@@ -100,10 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
53
  - !ruby/object:Gem::Version
101
54
  version: '0'
102
55
  requirements: []
103
- rubygems_version: 3.0.3
104
- signing_key:
56
+ rubygems_version: 3.5.23
57
+ signing_key:
105
58
  specification_version: 4
106
59
  summary: Delegator class that delegates ALL the things
107
- test_files:
108
- - spec/dumb_delegator_spec.rb
109
- - spec/spec_helper.rb
60
+ test_files: []
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- # Ignore all logfiles and tempfiles
2
- /tmp/
3
- /tags
4
-
5
- # Environment normalisation
6
- /.env
7
- /.rspec-local
8
- /.yardoc
9
- /lib/bundler/man/
10
-
11
- # Gem packaging stuff
12
- /*.gem
13
- /pkg/
14
-
15
- # Dependencies and such
16
- /.bundle
17
- /.ruby-version
18
- /Gemfile.lock
19
-
20
- # Spec and coverage housekeeping
21
- /coverage/
22
- /spec/rspec-status.txt
23
- /spec/reports
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- env:
4
- global:
5
- - CC_TEST_REPORTER_ID=de7062a4090ce5638b515a2cf9f2ab619de3e3f4ff439dc6cdad025c7a8d6b76
6
- rvm:
7
- - 2.4
8
- - 2.5
9
- - 2.6
10
- - 2.7
11
- - jruby
12
- cache: bundler
13
- before_install:
14
- - gem update --system --conservative
15
- - gem update bundler --conservative
16
- before_script:
17
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
18
- - chmod +x ./cc-test-reporter
19
- - ./cc-test-reporter before-build
20
- script:
21
- - bundle exec rake spec
22
- after_script:
23
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in dumb_delegator.gemspec
4
- gemspec
5
-
6
- gem "simplecov", group: :test, require: nil
7
- gem "pry-byebug", group: [:development, :test], platforms: [:ruby]
@@ -1,31 +0,0 @@
1
- require File.expand_path("../lib/dumb_delegator/version", __FILE__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.name = "dumb_delegator"
5
- gem.version = DumbDelegator::VERSION
6
- gem.required_ruby_version = ">= 2.4.0"
7
- gem.authors = ["Andy Lindeman", "Steven Harman"]
8
- gem.email = ["alindeman@gmail.com", "steven@harmanly.com"]
9
- gem.licenses = ["MIT"]
10
- gem.summary = "Delegator class that delegates ALL the things"
11
- gem.description = <<~EOD
12
- Delegator and SimpleDelegator in Ruby's stdlib are useful, but they pull in most of Kernel.
13
- This is not appropriate for many uses; for instance, delegation to Rails Models.
14
- DumbDelegator, on the other hand, delegates nearly everything to the wrapped object.
15
- EOD
16
- gem.homepage = "https://github.com/stevenharman/dumb_delegator"
17
-
18
- gem.metadata = {
19
- "changelog_uri" => "https://github.com/stevenharman/dumb_delegator/blob/master/CHANGELOG.md",
20
- "documentation_uri" => "https://rubydoc.info/gems/dumb_delegator",
21
- "source_code_uri" => "https://github.com/stevenharman/dumb_delegator",
22
- }
23
-
24
- gem.files = `git ls-files`.split($\)
25
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
26
- gem.require_paths = ["lib"]
27
-
28
- gem.add_development_dependency "pry"
29
- gem.add_development_dependency "rake", "~> 13.0"
30
- gem.add_development_dependency "rspec", "~> 3.9"
31
- end
@@ -1,230 +0,0 @@
1
- RSpec.describe DumbDelegator do
2
- subject(:dummy) { Wrapper.new(target) }
3
- let(:target) { Target.new }
4
-
5
- class Wrapper < DumbDelegator
6
- def wrapper_method
7
- "Method only on wrapper."
8
- end
9
-
10
- def common_method
11
- ["Method on wrapper.", super].join(" ")
12
- end
13
- end
14
-
15
- class Target
16
- def common_method
17
- "Method on target."
18
- end
19
-
20
- def target_method
21
- "Method only on target."
22
- end
23
-
24
- def query(*args)
25
- "queried with #{args}"
26
- end
27
-
28
- def with_block(&block)
29
- block.call
30
- end
31
- end
32
-
33
- it "delegates to the target object" do
34
- expect(dummy.target_method).to eq("Method only on target.")
35
- end
36
-
37
- it "delegates to the target object with arguments" do
38
- result = dummy.query("some_key", 42)
39
-
40
- expect(result).to eq(%(queried with ["some_key", 42]))
41
- end
42
-
43
- it "delegates to the target object with a block" do
44
- result = dummy.with_block { "block called!" }
45
-
46
- expect(result).to eq("block called!")
47
- end
48
-
49
- it "errors if the method is not defined on the wrapper nor the target" do
50
- expect {
51
- dummy.no_such_method
52
- }.to raise_error(NoMethodError)
53
- end
54
-
55
- it "responds to methods defined by child classes" do
56
- expect(dummy.wrapper_method).to eq("Method only on wrapper.")
57
- end
58
-
59
- it "responds to methods defined by child classes, and can super up to target" do
60
- expect(dummy.common_method).to eq("Method on wrapper. Method on target.")
61
- end
62
-
63
- it "delegates methods defined on Object" do
64
- expect(dummy.class).to eq(Target)
65
- end
66
-
67
- it "delegates methods defined on Kernel" do
68
- expect(target).to receive(:nil?)
69
- dummy.nil?
70
- end
71
-
72
- it "delegates bang (!) operator" do
73
- allow(target).to receive(:!) { "bang!" }
74
- expect(!dummy).to eq("bang!")
75
- end
76
-
77
- it "delegates object inequivalence" do
78
- allow(target).to receive(:!=).and_call_original
79
-
80
- expect(dummy != target).to be false
81
- end
82
-
83
- it "delegates object equivalence" do
84
- aggregate_failures do
85
- expect(dummy).to eql(target)
86
- expect(dummy == target).to be true
87
- end
88
- end
89
-
90
- it "delegates #===" do
91
- expect(dummy === target).to be true
92
- end
93
-
94
- it "delegates class checks" do
95
- aggregate_failures do
96
- expect(dummy.is_a?(Target)).to be(true)
97
- expect(dummy.kind_of?(Target)).to be(true) # rubocop:disable Style/ClassCheck
98
- expect(dummy.instance_of?(Target)).to be(true)
99
- end
100
- end
101
-
102
- it "does not delegate ::=== to the target's class" do
103
- aggregate_failures do
104
- expect(Target === dummy).to be false
105
- expect(DumbDelegator === dummy).to be true
106
- end
107
- end
108
-
109
- context "with a Module/Class's ::=== overridden via extension" do
110
- let(:target) { TargetWithTripleEqualExt.new }
111
-
112
- class TargetWithTripleEqualExt
113
- extend DumbDelegator::TripleEqualExt
114
- end
115
-
116
- it "delegates ::=== to the target's class" do
117
- aggregate_failures do
118
- expect(TargetWithTripleEqualExt === dummy).to be true
119
- expect(DumbDelegator === dummy).to be true
120
- end
121
- end
122
- end
123
-
124
- it "delegates instance_eval" do
125
- expect(target).to receive(:instance_eval)
126
- dummy.instance_eval { true }
127
- end
128
-
129
- it "delegates instance_exec" do
130
- expect(target).to receive(:instance_exec)
131
- dummy.instance_exec { true }
132
- end
133
-
134
- describe "#dup" do
135
- it "returns a shallow of itself, the delegator (not the underlying object)", objectspace: true do
136
- dupped = dummy.dup
137
-
138
- expect(ObjectSpace.each_object(DumbDelegator).map(&:__id__)).to include dupped.__id__
139
- end
140
- end
141
-
142
- describe "#clone" do
143
- it "returns a shallow of itself, the delegator (not the underlying object)", objectspace: true do
144
- cloned = dummy.clone
145
-
146
- expect(ObjectSpace.each_object(DumbDelegator).map(&:__id__)).to include cloned.__id__
147
- end
148
- end
149
-
150
- describe "marshaling" do
151
- let(:target) { Object.new }
152
-
153
- it "marshals and unmarshals itself, the delegator (not the underlying object)", objectspace: true do
154
- marshaled = Marshal.dump(dummy)
155
- unmarshaled = Marshal.load(marshaled)
156
-
157
- expect(ObjectSpace.each_object(DumbDelegator).map(&:__id__)).to include unmarshaled.__id__
158
- end
159
- end
160
-
161
- describe "#respond_to?" do
162
- [:equal?, :__id__, :__send__, :dup, :clone, :__getobj__, :__setobj__, :marshal_dump, :marshal_load, :respond_to?].each do |method|
163
- it "responds to #{method}" do
164
- expect(dummy.respond_to?(method)).to be true
165
- end
166
- end
167
-
168
- context "subclasses of DumbDelegator" do
169
- it "respond to methods defined on the subclass" do
170
- expect(dummy).to respond_to(:target_method)
171
- end
172
- end
173
- end
174
-
175
- describe "#__getobj__" do
176
- it "returns the target object" do
177
- expect(dummy.__getobj__).to equal(target)
178
- end
179
- end
180
-
181
- describe "#__setobj__" do
182
- it "resets the target object to a different object" do
183
- new_target = Target.new.tap do |nt|
184
- def nt.a_new_thing
185
- true
186
- end
187
- end
188
-
189
- dummy.__setobj__(new_target)
190
- expect(dummy.a_new_thing).to be true
191
- end
192
-
193
- it "cannot delegate to itself" do
194
- expect {
195
- dummy.__setobj__(dummy)
196
- dummy.common_method
197
- }.to raise_error(ArgumentError, "Delegation to self is not allowed.")
198
- end
199
- end
200
-
201
- describe "introspection capabilities" do
202
- it "provides a human-friendly representation of the delegator and wrapped object" do
203
- expect(dummy.inspect).to match(/#<Wrapper:\w+ obj: .+Target.+>/)
204
- end
205
-
206
- it "reports methods defined on the target" do
207
- expect(dummy.methods).to include(:target_method, :common_method)
208
- end
209
-
210
- it "reports methods defined on the wrapper" do
211
- expect(dummy.methods).to include(:wrapper_method, :common_method)
212
- end
213
-
214
- it "looks up a named method on the target" do
215
- method = dummy.method(:target_method)
216
- aggregate_failures do
217
- expect(method).not_to be_nil
218
- expect(method.receiver).to eq(target)
219
- end
220
- end
221
-
222
- it "looks up a named method on the wrapper" do
223
- method = dummy.method(:wrapper_method)
224
- aggregate_failures do
225
- expect(method).not_to be_nil
226
- expect(method.receiver).to equal(dummy)
227
- end
228
- end
229
- end
230
- end
data/spec/spec_helper.rb DELETED
@@ -1,38 +0,0 @@
1
- if ENV["CC_TEST_REPORTER_ID"] || ENV["COVERAGE"]
2
- require "simplecov"
3
- SimpleCov.start
4
- end
5
-
6
- require "pry"
7
- require File.expand_path("../lib/dumb_delegator", File.dirname(__FILE__))
8
-
9
- RSpec.configure do |config|
10
- config.expect_with :rspec do |expectations|
11
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
12
- end
13
-
14
- config.mock_with :rspec do |mocks|
15
- mocks.verify_partial_doubles = true
16
- end
17
-
18
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
19
- # have no way to turn it off -- the option exists only for backwards
20
- # compatibility in RSpec 3). It causes shared context metadata to be
21
- # inherited by the metadata hash of host groups and examples, rather than
22
- # triggering implicit auto-inclusion in groups with matching metadata.
23
- config.shared_context_metadata_behavior = :apply_to_host_groups
24
-
25
- config.filter_run_when_matching :focus
26
- config.example_status_persistence_file_path = "spec/rspec-status.txt"
27
- config.disable_monkey_patching!
28
- config.warnings = true
29
-
30
- if config.files_to_run.one?
31
- # Use the documentation formatter for detailed output,
32
- # unless a formatter has already been configured
33
- # (e.g. via a command-line flag).
34
- config.default_formatter = "doc"
35
- end
36
- config.order = :random
37
- Kernel.srand config.seed
38
- end