trailblazer-option 0.1.0 → 0.1.1

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: 0c5d6eb7b91e88296224c9a75b28fae91a4c91d58b36f1193ed8c13068e77261
4
- data.tar.gz: 4fb0d17ce2fbb30a2ac25c358c4a7b082e056aa406d646ac026991ba43ffe263
3
+ metadata.gz: b6002d9d525ee513b07f18ba89480e2a69be11892664186e8020c085e0286bf2
4
+ data.tar.gz: af25382707b80a01760a204861da7860ce4f60cd9a534b3015278de344cc8236
5
5
  SHA512:
6
- metadata.gz: 709e99594cbfb5810f6861a20294552ace31a364025e83a14709dee74e0339d8ed5e1e7ce9ac35bb18018864994a1ee81b1c8eea6115edf25f3d3d2b9febe22a
7
- data.tar.gz: 8ac22945f47ead2bc30d143f608dbaf257605fe95bad012c7328bde2aff2acf278bd3410854fe7787c0d0d3450f8cd8a28d4edc1f0d01c7f0bcc455f12b4ff17
6
+ metadata.gz: 1b3cfd6578fd2faf2a4d5e8f0df117ce387c01868e95056c3e6c0c4217129495ffd80f50a7ba05a166fcdefeab58931cccb5fbea845750b13c8b2e283044bc3d
7
+ data.tar.gz: fe6c2ce74b8ed5aac51ab0bc4fa773f2b8408f993667cb01299310806ed2d867c5d9724375dabc326d515107f79e59f6690522b02ee56fc68941364a87a08265
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.1
2
+
3
+ * Don't pass empty `keyword_arguments` for ruby <= 2.6.
4
+
1
5
  # 0.1.0
2
6
 
3
7
  * Separated from `trailblazer-context`, beginning its own world.
@@ -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
- def self.call!(value, *args, signal: :call, keyword_arguments: {}, **, &block)
7
- # {**keyword_arguments} gets removed automatically if it's an empty hash.
8
- # DISCUSS: is this a good practice?
9
- value.public_send(signal, *args, **keyword_arguments, &block)
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.
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Option
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
data/test/option_test.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require "test_helper"
2
2
 
3
3
  class OptionTest < Minitest::Spec
4
- def assert_result(result, block = nil)
5
- _(result).must_equal([{a: 1}, 2, {b: 3}, block])
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
- _(positional.inspect).must_equal %({:a=>1})
8
- _(keywords.inspect).must_equal %({:a=>2, :b=>3})
9
- end
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
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0")
77
- _(result).must_equal([1, 2, [3, 4]])
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.0
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-05 00:00:00.000000000 Z
11
+ date: 2021-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest