trailblazer-option 0.1.0 → 0.1.1
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/CHANGES.md +4 -0
- data/lib/trailblazer/option.rb +11 -4
- data/lib/trailblazer/option/version.rb +1 -1
- data/test/option_test.rb +48 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6002d9d525ee513b07f18ba89480e2a69be11892664186e8020c085e0286bf2
|
4
|
+
data.tar.gz: af25382707b80a01760a204861da7860ce4f60cd9a534b3015278de344cc8236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3cfd6578fd2faf2a4d5e8f0df117ce387c01868e95056c3e6c0c4217129495ffd80f50a7ba05a166fcdefeab58931cccb5fbea845750b13c8b2e283044bc3d
|
7
|
+
data.tar.gz: fe6c2ce74b8ed5aac51ab0bc4fa773f2b8408f993667cb01299310806ed2d867c5d9724375dabc326d515107f79e59f6690522b02ee56fc68941364a87a08265
|
data/CHANGES.md
CHANGED
data/lib/trailblazer/option.rb
CHANGED
@@ -3,10 +3,17 @@ module Trailblazer
|
|
3
3
|
# A call implementation invoking `value.(*args, **keyword_arguments)` and plainly forwarding all arguments.
|
4
4
|
# Override this for your own step strategy.
|
5
5
|
# @private
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
7
|
+
def self.call!(value, *args, signal: :call, keyword_arguments: {}, **, &block)
|
8
|
+
# NOTE: {**keyword_arguments} gets removed automatically if it's an empty hash.
|
9
|
+
value.public_send(signal, *args, **keyword_arguments, &block)
|
10
|
+
end
|
11
|
+
else
|
12
|
+
# Don't pass empty `keyword_arguments` because Ruby <= 2.6 passes an empty hash for `**{}`
|
13
|
+
def self.call!(value, *args, signal: :call, keyword_arguments: nil, **, &block)
|
14
|
+
return value.public_send(signal, *args, &block) unless keyword_arguments
|
15
|
+
value.public_send(signal, *args, **keyword_arguments, &block)
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
# Note that #evaluate_callable, #evaluate_proc and #evaluate_method drop most of the args.
|
data/test/option_test.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class OptionTest < Minitest::Spec
|
4
|
-
|
5
|
-
|
4
|
+
describe "positional and kws" do
|
5
|
+
def assert_result(result, block = nil)
|
6
|
+
_(result).must_equal([{a: 1}, 2, {b: 3}, block])
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
_(positional.inspect).must_equal %({:a=>1})
|
9
|
+
_(keywords.inspect).must_equal %({:a=>2, :b=>3})
|
10
|
+
end
|
10
11
|
|
11
|
-
describe "positional and kws" do
|
12
12
|
class Step
|
13
13
|
def with_positional_and_keywords(options, a: nil, **more_options, &block)
|
14
14
|
[options, a, more_options, block]
|
@@ -73,13 +73,8 @@ class OptionTest < Minitest::Spec
|
|
73
73
|
|
74
74
|
describe "positionals" do
|
75
75
|
def assert_result_pos(result)
|
76
|
-
|
77
|
-
|
78
|
-
_(positionals).must_equal [1, 2, 3, 4]
|
79
|
-
else
|
80
|
-
_(result).must_equal([1, 2, [3, 4, {}]])
|
81
|
-
_(positionals).must_equal [1, 2, 3, 4]
|
82
|
-
end
|
76
|
+
_(result).must_equal([1, 2, [3, 4]])
|
77
|
+
_(positionals).must_equal [1, 2, 3, 4]
|
83
78
|
end
|
84
79
|
|
85
80
|
# In Ruby < 3.0, {*args} will grab both positionals and keyword arguments.
|
@@ -167,4 +162,44 @@ class OptionTest < Minitest::Spec
|
|
167
162
|
assert_result_kws option.(keyword_arguments: keywords, exec_context: "something")
|
168
163
|
end
|
169
164
|
end
|
165
|
+
|
166
|
+
describe "no arguments" do
|
167
|
+
def assert_result_no_args(result)
|
168
|
+
_(result).must_equal([])
|
169
|
+
end
|
170
|
+
|
171
|
+
class Step
|
172
|
+
def with_no_args
|
173
|
+
[]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
class WithNoArgs
|
178
|
+
def self.call
|
179
|
+
[]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
WITH_NO_ARGS = -> { [] }
|
184
|
+
|
185
|
+
it ":method" do
|
186
|
+
step = Step.new
|
187
|
+
|
188
|
+
option = Trailblazer::Option(:with_no_args)
|
189
|
+
|
190
|
+
assert_result_no_args option.(exec_context: step)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "-> {} lambda" do
|
194
|
+
option = Trailblazer::Option(WITH_NO_ARGS)
|
195
|
+
|
196
|
+
assert_result_no_args option.(exec_context: "something")
|
197
|
+
end
|
198
|
+
|
199
|
+
it "callable" do
|
200
|
+
option = Trailblazer::Option(WithNoArgs)
|
201
|
+
|
202
|
+
assert_result_no_args option.(exec_context: "something")
|
203
|
+
end
|
204
|
+
end
|
170
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-option
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|