trailblazer-context 0.4.0 → 0.5.0
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/.github/workflows/ci.yml +17 -0
- data/CHANGES.md +4 -0
- data/Gemfile +1 -0
- data/README.md +0 -1
- data/lib/trailblazer-context.rb +0 -1
- data/lib/trailblazer/context/version.rb +1 -1
- metadata +6 -9
- data/.travis.yml +0 -13
- data/lib/trailblazer/option.rb +0 -47
- data/test/option_test.rb +0 -147
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2f68ea3324607256a507718188b38dcb7d0252f17bf49221b97b5e62be4d252
|
4
|
+
data.tar.gz: 6841b846db299f4c21352f03703c3b8780539e2eb59efbadf0bd1ecd780bb0d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ec16cbdba1cfeca1f3820e188dc5c8b449ff0295ee8849f5509297123b5c8b5046a9265206dff83051457e42aa7a7771387c82a4dfb5da6be9b2d93387b3aa
|
7
|
+
data.tar.gz: ee014562e35ad36355a8e62f18b8e8c2e497c86014aabac143ef308099e1f79f0b740d3f3e78fdeb0d9e5155b440ddb31e7f945da02fd48fc42eba1d7197f681
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
9
|
+
ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head]
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
17
|
+
- run: bundle exec rake
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,5 +5,4 @@ _Argument-specific data structures for Trailblazer._
|
|
5
5
|
This gem provides data structures needed across `Activity`, `Workflow` and `Operation`, such as the following.
|
6
6
|
|
7
7
|
* `Trailblazer::Context` implements the so-called `options` hash that is passed between steps and implements the keyword arguments.
|
8
|
-
* `Trailblazer::Option` is often used to wrap an option at compile-time and `call` it at runtime, which allows to have the common `-> ()`, `:method` or `Callable` pattern used for most options.
|
9
8
|
* `Trailblazer::ContainerChain` to implement chained lookups of properties and allow including containers such as `Dry::Container` in this chain. This is experimental.
|
data/lib/trailblazer-context.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -74,8 +74,8 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- ".github/workflows/ci.yml"
|
77
78
|
- ".gitignore"
|
78
|
-
- ".travis.yml"
|
79
79
|
- CHANGES.md
|
80
80
|
- Gemfile
|
81
81
|
- LICENSE
|
@@ -88,19 +88,17 @@ files:
|
|
88
88
|
- lib/trailblazer/context/container/with_aliases.rb
|
89
89
|
- lib/trailblazer/context/store/indifferent_access.rb
|
90
90
|
- lib/trailblazer/context/version.rb
|
91
|
-
- lib/trailblazer/option.rb
|
92
91
|
- test/benchmark/benchmark_helper.rb
|
93
92
|
- test/benchmark/indifferent_access_test.rb
|
94
93
|
- test/benchmark/indifferent_access_with_aliasing_test.rb
|
95
94
|
- test/context_test.rb
|
96
|
-
- test/option_test.rb
|
97
95
|
- test/test_helper.rb
|
98
96
|
- trailblazer-context.gemspec
|
99
97
|
homepage: https://trailblazer.to/
|
100
98
|
licenses:
|
101
99
|
- MIT
|
102
100
|
metadata: {}
|
103
|
-
post_install_message:
|
101
|
+
post_install_message:
|
104
102
|
rdoc_options: []
|
105
103
|
require_paths:
|
106
104
|
- lib
|
@@ -116,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
114
|
version: '0'
|
117
115
|
requirements: []
|
118
116
|
rubygems_version: 3.0.8
|
119
|
-
signing_key:
|
117
|
+
signing_key:
|
120
118
|
specification_version: 4
|
121
119
|
summary: Argument-specific data structures for Trailblazer.
|
122
120
|
test_files:
|
@@ -124,5 +122,4 @@ test_files:
|
|
124
122
|
- test/benchmark/indifferent_access_test.rb
|
125
123
|
- test/benchmark/indifferent_access_with_aliasing_test.rb
|
126
124
|
- test/context_test.rb
|
127
|
-
- test/option_test.rb
|
128
125
|
- test/test_helper.rb
|
data/.travis.yml
DELETED
data/lib/trailblazer/option.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
class Option
|
3
|
-
# A call implementation invoking `proc.(*args)` and plainly forwarding all arguments.
|
4
|
-
# Override this for your own step strategy (see KW#call!).
|
5
|
-
# @private
|
6
|
-
def self.call!(proc, *args, keyword_arguments: {}, **, &block)
|
7
|
-
# {**keyword_arguments} gets removed automatically if it's an empty hash.
|
8
|
-
# DISCUSS: is this a good practice?
|
9
|
-
proc.(*args, **keyword_arguments, &block)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Note that both #evaluate_callable and #evaluate_method drop most of the args.
|
13
|
-
# If you need those, override this class.
|
14
|
-
# @private
|
15
|
-
def self.evaluate_callable(proc, *args, **options, &block)
|
16
|
-
call!(proc, *args, **options, &block)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Make the context's instance method a "lambda" and reuse #call!.
|
20
|
-
# @private
|
21
|
-
def self.evaluate_method(proc, *args, exec_context: raise("No :exec_context given."), **options, &block)
|
22
|
-
call!(exec_context.method(proc), *args, **options, &block)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Generic builder for a callable "option".
|
26
|
-
# @param call_implementation [Class, Module] implements the process of calling the proc
|
27
|
-
# while passing arguments/options to it in a specific style (e.g. kw args, step interface).
|
28
|
-
# @return [Proc] when called, this proc will evaluate its option (at run-time).
|
29
|
-
def self.build(proc)
|
30
|
-
if proc.is_a? Symbol
|
31
|
-
->(*args, **kws, &block) { Option.evaluate_method(proc, *args, **kws, &block) }
|
32
|
-
else
|
33
|
-
->(*args, **kws, &block) {
|
34
|
-
Option.evaluate_callable(proc, *args, **kws, &block) }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.KW(proc)
|
39
|
-
raise "The `Option::KW()` method has been removed in trailblazer-context-0.4.
|
40
|
-
Please use `Option(task, keyword_arguments: {...})` instead. Check https://trailblazer.to/2.1/docs/trailblazer.html#trailblazer-context-option"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
# @note This might go to trailblazer-args along with `Context` at some point.
|
44
|
-
def self.Option(proc)
|
45
|
-
Option.build(proc)
|
46
|
-
end
|
47
|
-
end
|
data/test/option_test.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class OptionTest < Minitest::Spec
|
4
|
-
def assert_result(result, block = nil)
|
5
|
-
_(result).must_equal([{a: 1}, 2, {b: 3}, block])
|
6
|
-
|
7
|
-
_(positional.inspect).must_equal %({:a=>1})
|
8
|
-
_(keywords.inspect).must_equal %({:a=>2, :b=>3})
|
9
|
-
end
|
10
|
-
|
11
|
-
# it "what" do
|
12
|
-
# ctx = {params: 1}
|
13
|
-
# tmp_options = {constant: Object, model: Module}
|
14
|
-
|
15
|
-
# builder = Class.new do
|
16
|
-
# def builder(ctx, constant:, model:, **)
|
17
|
-
# raise model.inspect
|
18
|
-
# end
|
19
|
-
# end.new
|
20
|
-
|
21
|
-
# circuit_options = {exec_context: builder}
|
22
|
-
|
23
|
-
# # Trailblazer::Option(:builder, ).(ctx, tmp_options, **circuit_options.merge(keyword_arguments: tmp_options)) # calls {def default_contract!(options, constant:, model:, **)}
|
24
|
-
# Trailblazer::Option(:builder, ).(ctx, **circuit_options.merge(keyword_arguments: tmp_options)) # calls {def default_contract!(options, constant:, model:, **)}
|
25
|
-
# end
|
26
|
-
|
27
|
-
describe "positional and kws" do
|
28
|
-
class Step
|
29
|
-
def with_positional_and_keywords(options, a: nil, **more_options, &block)
|
30
|
-
[options, a, more_options, block]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
WITH_POSITIONAL_AND_KEYWORDS = ->(options, a: nil, **more_options, &block) do
|
35
|
-
[options, a, more_options, block]
|
36
|
-
end
|
37
|
-
|
38
|
-
class WithPositionalAndKeywords
|
39
|
-
def self.call(options, a: nil, **more_options, &block)
|
40
|
-
[options, a, more_options, block]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
let(:positional) { {a: 1} }
|
45
|
-
let(:keywords) { {a: 2, b: 3} }
|
46
|
-
|
47
|
-
let(:block) { ->(*) { snippet } }
|
48
|
-
|
49
|
-
describe ":method" do
|
50
|
-
let(:option) { Trailblazer::Option(:with_positional_and_keywords) }
|
51
|
-
|
52
|
-
it "passes through all args" do
|
53
|
-
step = Step.new
|
54
|
-
|
55
|
-
# positional = { a: 1 }
|
56
|
-
# keywords = { a: 2, b: 3 }
|
57
|
-
assert_result option.(positional, keyword_arguments: keywords, exec_context: step)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "allows passing a block, too" do
|
61
|
-
step = Step.new
|
62
|
-
|
63
|
-
assert_result option.(positional, keyword_arguments: keywords, exec_context: step, &block), block
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "lambda" do
|
68
|
-
let(:option) { Trailblazer::Option(WITH_POSITIONAL_AND_KEYWORDS) }
|
69
|
-
|
70
|
-
it "-> {} lambda" do
|
71
|
-
assert_result option.(positional, **{keyword_arguments: keywords})
|
72
|
-
end
|
73
|
-
|
74
|
-
it "allows passing a block, too" do
|
75
|
-
assert_result option.(positional, **{keyword_arguments: keywords}, &block), block
|
76
|
-
end
|
77
|
-
|
78
|
-
it "doesn't mind :exec_context" do
|
79
|
-
assert_result option.(positional, keyword_arguments: keywords, exec_context: "bogus")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "Callable" do
|
84
|
-
let(:option) { Trailblazer::Option(WithPositionalAndKeywords) }
|
85
|
-
|
86
|
-
it "passes through all args" do
|
87
|
-
assert_result option.(positional, keyword_arguments: keywords, exec_context: nil)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "allows passing a block, too" do
|
91
|
-
assert_result option.(positional, keyword_arguments: keywords, exec_context: nil, &block), block
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "positionals" do
|
97
|
-
def assert_result_pos(result)
|
98
|
-
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0")
|
99
|
-
_(result).must_equal([1, 2, [3, 4]])
|
100
|
-
_(positionals).must_equal [1, 2, 3, 4]
|
101
|
-
else
|
102
|
-
_(result).must_equal([1, 2, [3, 4, {}]])
|
103
|
-
_(positionals).must_equal [1, 2, 3, 4]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# In Ruby < 3.0, {*args} will grab both positionals and keyword arguments.
|
108
|
-
class Step
|
109
|
-
def with_positionals(a, b, *args)
|
110
|
-
[a, b, args]
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
WITH_POSITIONALS = ->(a, b, *args) do
|
115
|
-
[a, b, args]
|
116
|
-
end
|
117
|
-
|
118
|
-
class WithPositionals
|
119
|
-
def self.call(a, b, *args)
|
120
|
-
[a, b, args]
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
let(:positionals) { [1, 2, 3, 4] }
|
125
|
-
|
126
|
-
it ":method" do
|
127
|
-
step = Step.new
|
128
|
-
|
129
|
-
option = Trailblazer::Option(:with_positionals)
|
130
|
-
|
131
|
-
assert_result_pos option.(*positionals, exec_context: step)
|
132
|
-
end
|
133
|
-
|
134
|
-
it "-> {} lambda" do
|
135
|
-
option = Trailblazer::Option(WITH_POSITIONALS)
|
136
|
-
|
137
|
-
assert_result_pos option.(*positionals, exec_context: "something")
|
138
|
-
end
|
139
|
-
|
140
|
-
it "callable" do
|
141
|
-
option = Trailblazer::Option(WithPositionals)
|
142
|
-
|
143
|
-
assert_result_pos option.(*positionals, exec_context: "something")
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|