method_object 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 +4 -4
- data/lib/method_object.rb +16 -15
- data/spec/method_object_spec.rb +19 -0
- data/spec/spec_helper.rb +3 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f253b26368bed785b3953ec65e8deca17d637232b67607c042eea7a93cf1238
|
4
|
+
data.tar.gz: 25c6c4c527708a4a7f1cd614fa89c1d0769358abf639ff2fb90d2667cc08e84e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1fcc4865de7c9c99e9d9b836e32d6b9d6a983bb0266ef46878021351982a1a03a0d2ac8e92c0f7000918493830d6a8e7eec7040186fde37603341d1b61571d6
|
7
|
+
data.tar.gz: 3f0ffd9158b17a45fcae5aa46c55fc6d4d2ffc2086cb43615bcc11b1a8b02d8cf265ce759cd01bbbced1546a043955bf1389b94dc9eccdc4c898209f2f5ea9b1
|
data/lib/method_object.rb
CHANGED
@@ -8,33 +8,34 @@ module MethodObject
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def call(*args, &block)
|
12
|
-
__check_for_unknown_options(*args)
|
13
|
-
|
11
|
+
def call(*args, **kwargs, &block)
|
12
|
+
__check_for_unknown_options(*args, **kwargs)
|
13
|
+
|
14
|
+
if kwargs.empty?
|
15
|
+
# Preventing `Passing the keyword argument as the last hash parameter is deprecated`
|
16
|
+
new(*args).call(&block)
|
17
|
+
else
|
18
|
+
new(*args, **kwargs).call(&block)
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
|
-
#
|
22
|
+
# Overriding the implementation of `#param` in the `dry-initializer` gem.
|
23
|
+
# Because of the positioning of multiple params, params can never be omitted in a method object.
|
17
24
|
def param(name, type = nil, **opts, &block)
|
18
25
|
raise ArgumentError, "Default value for param not allowed - #{name}" if opts.key? :default
|
19
26
|
raise ArgumentError, "Optional params not supported - #{name}" if opts.fetch(:optional, false)
|
20
27
|
|
21
|
-
|
22
|
-
self
|
28
|
+
super
|
23
29
|
end
|
24
30
|
|
25
|
-
|
26
|
-
def assign(variable, to:)
|
27
|
-
warn 'MethodObject.assign is deprecated. ' \
|
28
|
-
"Please use this instead: `option #{variable.inspect}, default: ...`"
|
29
|
-
option variable, default: to
|
30
|
-
end
|
31
|
-
|
32
|
-
def __check_for_unknown_options(*args)
|
31
|
+
def __check_for_unknown_options(*args, **kwargs)
|
33
32
|
return if __defined_options.empty?
|
34
33
|
|
35
|
-
|
34
|
+
# Checking params
|
35
|
+
opts = args.drop(__defined_params.length).first || kwargs
|
36
36
|
raise ArgumentError, "Unexpected argument #{opts}" unless opts.is_a? Hash
|
37
37
|
|
38
|
+
# Checking options
|
38
39
|
unknown_options = opts.keys - __defined_options
|
39
40
|
message = "Key(s) #{unknown_options} not found in #{__defined_options}"
|
40
41
|
raise KeyError, message if unknown_options.any?
|
data/spec/method_object_spec.rb
CHANGED
@@ -26,6 +26,16 @@ class ExampleMethodObject
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
class InspectionMethodObject
|
30
|
+
include MethodObject
|
31
|
+
|
32
|
+
param :something
|
33
|
+
|
34
|
+
def call
|
35
|
+
something
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
29
39
|
RSpec.describe MethodObject do
|
30
40
|
describe '.param' do
|
31
41
|
context 'when defining a default value' do
|
@@ -93,5 +103,14 @@ RSpec.describe MethodObject do
|
|
93
103
|
end.to raise_error ArgumentError, 'Unexpected argument boom!'
|
94
104
|
end
|
95
105
|
end
|
106
|
+
|
107
|
+
context 'with one param' do
|
108
|
+
it 'has the argument that was passed in' do
|
109
|
+
object = Object.new
|
110
|
+
result = InspectionMethodObject.call object
|
111
|
+
|
112
|
+
expect(result).to be object
|
113
|
+
end
|
114
|
+
end
|
96
115
|
end
|
97
116
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'method_object'
|
3
3
|
|
4
|
+
require 'warning'
|
5
|
+
Warning.process { raise "This gem should not cause deprecation warnings, but it did: #{_1}" }
|
6
|
+
|
4
7
|
RSpec.configure do |config|
|
5
8
|
# Enable flags like --only-failures and --next-failure
|
6
9
|
config.example_status_persistence_file_path = '.rspec_status'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bukowskis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-initializer
|
@@ -102,14 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
105
|
+
version: 2.7.0
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.0.
|
112
|
+
rubygems_version: 3.0.3.1
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Combining the method object pattern with DRY initialization
|