trailblazer-context 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68c328cb817dbf1889d8e4619afa0b950786a839d8685c145ac9cda543b63c5b
4
- data.tar.gz: 3bbe468cf341ebb429715983c3ea284b02251eedfe0084b6225252fbf5240e4b
3
+ metadata.gz: 5c491d5456a100bdb4853e02af240d56039864b7589e576db32f82f1683375e6
4
+ data.tar.gz: 0f4b8b205289cb71b2cb7bca8e562312bb184e681e501af6741e37a82b7ff298
5
5
  SHA512:
6
- metadata.gz: 0001ec043007eec13ac0ce4c836f406a4fbfcfee8c759fb85c2059d0fffce774423d8986f504a9b0fc36c31e4d0bd75673a02f2d1e9f92b1229f95af3115f029
7
- data.tar.gz: 85848da20e2f7639183f4cefc2095294f183f3217927b8ed573ba307ed122871549f1a5409d3369e767a896f8a64c18af598e30fbf10bc33de3918e546e2c6dd
6
+ metadata.gz: 022fccd76fa9936a7fd0b80070d703cd2f64f5cf7c96c03831d06e7160cf8d2b2581cfa3debaab6bcb106208f91cb9ff5db2a7e7957aab388cdbdc5ccc1c9f9e
7
+ data.tar.gz: 1ff63b11983902dbd79630be7535095f62812d7522378fff42944bd291ad5e2b7dce55d4b7e985b9ae575f488d65109dcbac2886c51e548f3061095bb54e9a34
@@ -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
@@ -1,3 +1,11 @@
1
+ # 0.5.1
2
+
3
+ * Fix `ctx.delete` to return the value being deleted.
4
+
5
+ # 0.5.0
6
+
7
+ * Extracted `Option` into its own repository, `trailblazer-option` ✨
8
+
1
9
  # 0.4.0
2
10
 
3
11
  * Ready for Ruby 3.0. :heart:
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
+ gem "benchmark-ips"
4
5
  gem "minitest-line"
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.
@@ -50,8 +50,8 @@ module Trailblazer
50
50
  alias_method :store, :[]=
51
51
 
52
52
  def delete(key)
53
- @replica.delete(key)
54
53
  @mutable_options.delete(key)
54
+ @replica.delete(key)
55
55
  end
56
56
 
57
57
  def merge(other_hash)
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  module Context
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -1,3 +1,2 @@
1
1
  require "trailblazer/context/version"
2
2
  require "trailblazer/context"
3
- require "trailblazer/option"
data/test/context_test.rb CHANGED
@@ -123,8 +123,9 @@ class ContextWithIndifferentAccessTest < Minitest::Spec
123
123
 
124
124
  # delete
125
125
  ctx[:model] = Object
126
- ctx.delete 'model'
126
+ value = ctx.delete 'model'
127
127
 
128
+ _(value).must_equal Object
128
129
  _(ctx.key?(:model)).must_equal false
129
130
  _(ctx.key?("model")).must_equal false
130
131
 
@@ -202,8 +203,9 @@ class ContextWithIndifferentAccessTest < Minitest::Spec
202
203
 
203
204
  # delete
204
205
  ctx[:result] = Object
205
- ctx.delete :result
206
+ value = ctx.delete :result
206
207
 
208
+ _(value).must_equal Object
207
209
  _(ctx.key?(:result)).must_equal false
208
210
  _(ctx.key?("result")).must_equal false
209
211
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["apotonick@gmail.com"]
10
10
 
11
11
  spec.summary = "Argument-specific data structures for Trailblazer."
12
- spec.description = "Argument-specific data structures for Trailblazer such as Context, Option and ContainerChain."
12
+ spec.description = "Argument-specific data structures for Trailblazer such as Context and ContainerChain."
13
13
  spec.homepage = "https://trailblazer.to/"
14
14
  spec.licenses = ["MIT"]
15
15
 
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.0
4
+ version: 0.5.1
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-02-26 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -66,16 +66,16 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Argument-specific data structures for Trailblazer such as Context, Option
70
- and ContainerChain.
69
+ description: Argument-specific data structures for Trailblazer such as Context and
70
+ ContainerChain.
71
71
  email:
72
72
  - apotonick@gmail.com
73
73
  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
@@ -115,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
113
  - !ruby/object:Gem::Version
116
114
  version: '0'
117
115
  requirements: []
118
- rubygems_version: 3.0.8
119
- signing_key:
116
+ rubygems_version: 3.3.18
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
@@ -1,13 +0,0 @@
1
- language: ruby
2
- before_install: gem install bundler
3
- cache: bundler
4
- rvm:
5
- - ruby-head
6
- - 3.0
7
- - 2.7
8
- - 2.6
9
- - 2.5
10
- - 2.4
11
- jobs:
12
- allow_failures:
13
- - rvm: ruby-head
@@ -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