trailblazer-context 0.2.0 → 0.4.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/.gitignore +1 -0
- data/.travis.yml +10 -5
- data/CHANGES.md +40 -0
- data/Gemfile +0 -1
- data/LICENSE +1 -1
- data/Rakefile +5 -2
- data/lib/trailblazer-context.rb +1 -0
- data/lib/trailblazer/container_chain.rb +0 -2
- data/lib/trailblazer/context.rb +13 -84
- data/lib/trailblazer/context/container.rb +100 -0
- data/lib/trailblazer/context/container/with_aliases.rb +102 -0
- data/lib/trailblazer/context/store/indifferent_access.rb +36 -0
- data/lib/trailblazer/context/version.rb +2 -2
- data/lib/trailblazer/option.rb +26 -57
- data/test/benchmark/benchmark_helper.rb +32 -0
- data/test/benchmark/indifferent_access_test.rb +89 -0
- data/test/benchmark/indifferent_access_with_aliasing_test.rb +73 -0
- data/test/context_test.rb +201 -91
- data/test/option_test.rb +34 -73
- data/test/test_helper.rb +0 -1
- data/trailblazer-context.gemspec +4 -3
- metadata +21 -17
- data/.rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +0 -136
- data/.rubocop.yml +0 -40
- data/lib/trailblazer/context/aliasing.rb +0 -36
- data/lib/trailblazer/context/indifferent_access.rb +0 -35
data/test/option_test.rb
CHANGED
@@ -2,12 +2,28 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
class OptionTest < Minitest::Spec
|
4
4
|
def assert_result(result, block = nil)
|
5
|
-
result.must_equal([{a: 1}, 2, {b: 3}, block])
|
5
|
+
_(result).must_equal([{a: 1}, 2, {b: 3}, block])
|
6
6
|
|
7
|
-
positional.inspect.must_equal %({:a=>1})
|
8
|
-
keywords.inspect.must_equal %({:a=>2, :b=>3})
|
7
|
+
_(positional.inspect).must_equal %({:a=>1})
|
8
|
+
_(keywords.inspect).must_equal %({:a=>2, :b=>3})
|
9
9
|
end
|
10
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
|
+
|
11
27
|
describe "positional and kws" do
|
12
28
|
class Step
|
13
29
|
def with_positional_and_keywords(options, a: nil, **more_options, &block)
|
@@ -38,13 +54,13 @@ class OptionTest < Minitest::Spec
|
|
38
54
|
|
39
55
|
# positional = { a: 1 }
|
40
56
|
# keywords = { a: 2, b: 3 }
|
41
|
-
assert_result option.(positional, keywords, exec_context: step)
|
57
|
+
assert_result option.(positional, keyword_arguments: keywords, exec_context: step)
|
42
58
|
end
|
43
59
|
|
44
60
|
it "allows passing a block, too" do
|
45
61
|
step = Step.new
|
46
62
|
|
47
|
-
assert_result option.(positional, keywords,
|
63
|
+
assert_result option.(positional, keyword_arguments: keywords, exec_context: step, &block), block
|
48
64
|
end
|
49
65
|
end
|
50
66
|
|
@@ -52,15 +68,15 @@ class OptionTest < Minitest::Spec
|
|
52
68
|
let(:option) { Trailblazer::Option(WITH_POSITIONAL_AND_KEYWORDS) }
|
53
69
|
|
54
70
|
it "-> {} lambda" do
|
55
|
-
assert_result option.(positional, keywords
|
71
|
+
assert_result option.(positional, **{keyword_arguments: keywords})
|
56
72
|
end
|
57
73
|
|
58
74
|
it "allows passing a block, too" do
|
59
|
-
assert_result option.(positional, keywords
|
75
|
+
assert_result option.(positional, **{keyword_arguments: keywords}, &block), block
|
60
76
|
end
|
61
77
|
|
62
78
|
it "doesn't mind :exec_context" do
|
63
|
-
assert_result option.(positional, keywords, exec_context: "bogus")
|
79
|
+
assert_result option.(positional, keyword_arguments: keywords, exec_context: "bogus")
|
64
80
|
end
|
65
81
|
end
|
66
82
|
|
@@ -68,21 +84,27 @@ class OptionTest < Minitest::Spec
|
|
68
84
|
let(:option) { Trailblazer::Option(WithPositionalAndKeywords) }
|
69
85
|
|
70
86
|
it "passes through all args" do
|
71
|
-
assert_result option.(positional, keywords, exec_context: nil)
|
87
|
+
assert_result option.(positional, keyword_arguments: keywords, exec_context: nil)
|
72
88
|
end
|
73
89
|
|
74
90
|
it "allows passing a block, too" do
|
75
|
-
assert_result option.(positional, keywords,
|
91
|
+
assert_result option.(positional, keyword_arguments: keywords, exec_context: nil, &block), block
|
76
92
|
end
|
77
93
|
end
|
78
94
|
end
|
79
95
|
|
80
96
|
describe "positionals" do
|
81
97
|
def assert_result_pos(result)
|
82
|
-
|
83
|
-
|
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
|
84
105
|
end
|
85
106
|
|
107
|
+
# In Ruby < 3.0, {*args} will grab both positionals and keyword arguments.
|
86
108
|
class Step
|
87
109
|
def with_positionals(a, b, *args)
|
88
110
|
[a, b, args]
|
@@ -122,65 +144,4 @@ class OptionTest < Minitest::Spec
|
|
122
144
|
end
|
123
145
|
end
|
124
146
|
|
125
|
-
describe "Option::KW" do
|
126
|
-
def assert_result_kws(result)
|
127
|
-
result.must_equal([{a: 1, b: 2, c: 3}, 1, 2, {c: 3}])
|
128
|
-
end
|
129
|
-
|
130
|
-
class Step
|
131
|
-
def with_kws(options, a: nil, b: nil, **rest)
|
132
|
-
[options, a, b, rest]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
module Task
|
137
|
-
def self.with_kws(options, a: nil, b: nil, **rest)
|
138
|
-
[options, a, b, rest]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
WITH_KWS = ->(options, a: nil, b: nil, **rest) do
|
143
|
-
[options, a, b, rest]
|
144
|
-
end
|
145
|
-
|
146
|
-
class WithKWs
|
147
|
-
def self.call(options, a: nil, b: nil, **rest)
|
148
|
-
[options, a, b, rest]
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
let(:options) { {a: 1, b: 2, c: 3} }
|
153
|
-
|
154
|
-
it ":method" do
|
155
|
-
step = Step.new
|
156
|
-
|
157
|
-
option = Trailblazer::Option::KW(:with_kws)
|
158
|
-
|
159
|
-
assert_result_kws option.(options, exec_context: step)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "Method instance" do
|
163
|
-
option = Trailblazer::Option::KW(Task.method(:with_kws))
|
164
|
-
|
165
|
-
assert_result_kws option.(options, {})
|
166
|
-
end
|
167
|
-
|
168
|
-
it "-> {} lambda" do
|
169
|
-
option = Trailblazer::Option::KW(WITH_KWS)
|
170
|
-
|
171
|
-
assert_result_kws option.(options, {})
|
172
|
-
end
|
173
|
-
|
174
|
-
it "lambda ignores :exec_context" do
|
175
|
-
option = Trailblazer::Option::KW(WITH_KWS)
|
176
|
-
|
177
|
-
assert_result_kws option.(options, exec_context: "something")
|
178
|
-
end
|
179
|
-
|
180
|
-
it "callable" do
|
181
|
-
option = Trailblazer::Option::KW(WithKWs)
|
182
|
-
|
183
|
-
assert_result_kws option.(options, {})
|
184
|
-
end
|
185
|
-
end
|
186
147
|
end
|
data/test/test_helper.rb
CHANGED
data/trailblazer-context.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = "Argument-specific data structures for Trailblazer."
|
12
12
|
spec.description = "Argument-specific data structures for Trailblazer such as Context, Option and ContainerChain."
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://trailblazer.to/"
|
14
14
|
spec.licenses = ["MIT"]
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -20,11 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
+
spec.add_dependency "hashie", ">= 3.0.0"
|
24
|
+
|
23
25
|
spec.add_development_dependency "bundler"
|
24
26
|
spec.add_development_dependency "minitest"
|
25
27
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rubocop"
|
27
28
|
|
28
29
|
# maybe we could remove this?
|
29
|
-
spec.required_ruby_version = ">= 2.
|
30
|
+
spec.required_ruby_version = ">= 2.1.0"
|
30
31
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: hashie
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -75,8 +75,6 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
|
-
- ".rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml"
|
79
|
-
- ".rubocop.yml"
|
80
78
|
- ".travis.yml"
|
81
79
|
- CHANGES.md
|
82
80
|
- Gemfile
|
@@ -86,15 +84,19 @@ files:
|
|
86
84
|
- lib/trailblazer-context.rb
|
87
85
|
- lib/trailblazer/container_chain.rb
|
88
86
|
- lib/trailblazer/context.rb
|
89
|
-
- lib/trailblazer/context/
|
90
|
-
- lib/trailblazer/context/
|
87
|
+
- lib/trailblazer/context/container.rb
|
88
|
+
- lib/trailblazer/context/container/with_aliases.rb
|
89
|
+
- lib/trailblazer/context/store/indifferent_access.rb
|
91
90
|
- lib/trailblazer/context/version.rb
|
92
91
|
- lib/trailblazer/option.rb
|
92
|
+
- test/benchmark/benchmark_helper.rb
|
93
|
+
- test/benchmark/indifferent_access_test.rb
|
94
|
+
- test/benchmark/indifferent_access_with_aliasing_test.rb
|
93
95
|
- test/context_test.rb
|
94
96
|
- test/option_test.rb
|
95
97
|
- test/test_helper.rb
|
96
98
|
- trailblazer-context.gemspec
|
97
|
-
homepage:
|
99
|
+
homepage: https://trailblazer.to/
|
98
100
|
licenses:
|
99
101
|
- MIT
|
100
102
|
metadata: {}
|
@@ -106,19 +108,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
108
|
requirements:
|
107
109
|
- - ">="
|
108
110
|
- !ruby/object:Gem::Version
|
109
|
-
version: 2.
|
111
|
+
version: 2.1.0
|
110
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
113
|
requirements:
|
112
114
|
- - ">="
|
113
115
|
- !ruby/object:Gem::Version
|
114
116
|
version: '0'
|
115
117
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.7.3
|
118
|
+
rubygems_version: 3.0.8
|
118
119
|
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: Argument-specific data structures for Trailblazer.
|
121
122
|
test_files:
|
123
|
+
- test/benchmark/benchmark_helper.rb
|
124
|
+
- test/benchmark/indifferent_access_test.rb
|
125
|
+
- test/benchmark/indifferent_access_with_aliasing_test.rb
|
122
126
|
- test/context_test.rb
|
123
127
|
- test/option_test.rb
|
124
128
|
- test/test_helper.rb
|
@@ -1,136 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
TargetRubyVersion: 2.5.0
|
3
|
-
DisplayCopNames: true
|
4
|
-
Layout/CaseIndentation:
|
5
|
-
IndentOneStep: true
|
6
|
-
Layout/FirstArrayElementLineBreak:
|
7
|
-
Enabled: true
|
8
|
-
Layout/FirstHashElementLineBreak:
|
9
|
-
Enabled: true
|
10
|
-
Layout/FirstMethodArgumentLineBreak:
|
11
|
-
Enabled: true
|
12
|
-
Layout/FirstMethodParameterLineBreak:
|
13
|
-
Enabled: true
|
14
|
-
Layout/MultilineAssignmentLayout:
|
15
|
-
Enabled: true
|
16
|
-
EnforcedStyle: same_line
|
17
|
-
Layout/SpaceInsideHashLiteralBraces:
|
18
|
-
EnforcedStyle: no_space
|
19
|
-
Metrics/LineLength:
|
20
|
-
Max: 130
|
21
|
-
Metrics/ParameterLists:
|
22
|
-
Max: 5
|
23
|
-
Naming/VariableNumber:
|
24
|
-
EnforcedStyle: snake_case
|
25
|
-
Style/AndOr:
|
26
|
-
EnforcedStyle: conditionals
|
27
|
-
Style/AutoResourceCleanup:
|
28
|
-
Enabled: true
|
29
|
-
Style/CollectionMethods:
|
30
|
-
Enabled: true
|
31
|
-
Style/Documentation:
|
32
|
-
Enabled: false
|
33
|
-
Style/EmptyLiteral:
|
34
|
-
Enabled: false
|
35
|
-
Style/EmptyMethod:
|
36
|
-
EnforcedStyle: expanded
|
37
|
-
Style/FormatStringToken:
|
38
|
-
EnforcedStyle: template
|
39
|
-
Style/ImplicitRuntimeError:
|
40
|
-
Enabled: true
|
41
|
-
Style/MethodCalledOnDoEndBlock:
|
42
|
-
Enabled: true
|
43
|
-
Style/MethodDefParentheses:
|
44
|
-
EnforcedStyle: require_parentheses
|
45
|
-
Style/MissingElse:
|
46
|
-
Enabled: true
|
47
|
-
EnforcedStyle: case
|
48
|
-
Style/NumericLiterals:
|
49
|
-
Enabled: false
|
50
|
-
Style/OptionHash:
|
51
|
-
Enabled: true
|
52
|
-
Style/PercentLiteralDelimiters:
|
53
|
-
PreferredDelimiters:
|
54
|
-
"%w": "[]"
|
55
|
-
"%W": "[]"
|
56
|
-
"%i": "[]"
|
57
|
-
"%I": "[]"
|
58
|
-
"%r": "()"
|
59
|
-
Style/ReturnNil:
|
60
|
-
Enabled: true
|
61
|
-
Style/SafeNavigation:
|
62
|
-
Enabled: false
|
63
|
-
Style/Send:
|
64
|
-
Enabled: true
|
65
|
-
Style/SignalException:
|
66
|
-
EnforcedStyle: semantic
|
67
|
-
Style/StringLiterals:
|
68
|
-
EnforcedStyle: double_quotes
|
69
|
-
Style/StringLiteralsInInterpolation:
|
70
|
-
EnforcedStyle: double_quotes
|
71
|
-
Style/StringMethods:
|
72
|
-
Enabled: true
|
73
|
-
Style/SymbolArray:
|
74
|
-
Enabled: true
|
75
|
-
# this allows in rspec to have expect { } with multiple lines
|
76
|
-
Style/BlockDelimiters:
|
77
|
-
EnforcedStyle: braces_for_chaining
|
78
|
-
Layout/EndOfLine:
|
79
|
-
Enabled: false
|
80
|
-
# don't need these checks in test folders
|
81
|
-
Metrics/ModuleLength:
|
82
|
-
Exclude:
|
83
|
-
- "spec/**/*"
|
84
|
-
- "test/**/*"
|
85
|
-
Metrics/BlockLength:
|
86
|
-
Exclude:
|
87
|
-
- "spec/**/*"
|
88
|
-
- "test/**/*"
|
89
|
-
- "*.gemspec" # definitely not in the gemspec
|
90
|
-
Metrics/MethodLength:
|
91
|
-
Max: 20
|
92
|
-
Lint/UnreachableCode:
|
93
|
-
Description: 'Unreachable code.'
|
94
|
-
Enabled: false
|
95
|
-
Lint/Void:
|
96
|
-
Enabled: false
|
97
|
-
Layout/AlignHash:
|
98
|
-
EnforcedLastArgumentHashStyle: ignore_implicit
|
99
|
-
Metrics/AbcSize:
|
100
|
-
Max: 25
|
101
|
-
Style/LambdaCall:
|
102
|
-
Enabled: false
|
103
|
-
Style/Semicolon:
|
104
|
-
Enabled: false
|
105
|
-
Naming/UncommunicativeMethodParamName:
|
106
|
-
Enabled: false
|
107
|
-
Style/ClassAndModuleChildren:
|
108
|
-
Enabled: false
|
109
|
-
Layout/LeadingCommentSpace:
|
110
|
-
Exclude:
|
111
|
-
- 'test/docs/**/*'
|
112
|
-
Layout/AlignHash:
|
113
|
-
EnforcedHashRocketStyle: table
|
114
|
-
Style/FrozenStringLiteralComment:
|
115
|
-
Enabled: false
|
116
|
-
Layout/AlignHash:
|
117
|
-
EnforcedColonStyle: table
|
118
|
-
SingleLineMethods:
|
119
|
-
Enabled: false
|
120
|
-
Style/Lambda:
|
121
|
-
EnforcedStyle: literal
|
122
|
-
Style/AsciiComments:
|
123
|
-
Enabled: false
|
124
|
-
Style/CollectionMethods:
|
125
|
-
Enabled: false
|
126
|
-
Style/RedundantReturn:
|
127
|
-
Enabled: false
|
128
|
-
Style/PercentLiteralDelimiters:
|
129
|
-
PreferredDelimiters:
|
130
|
-
default: {}
|
131
|
-
"%q": '()'
|
132
|
-
"%r": '{}'
|
133
|
-
"%w": '[]'
|
134
|
-
"%": '{}'
|
135
|
-
Style/HashSyntax:
|
136
|
-
Enabled: false
|
data/.rubocop.yml
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
TargetRubyVersion: 2.2
|
3
|
-
|
4
|
-
inherit_from:
|
5
|
-
- https://raw.githubusercontent.com/trailblazer/meta/master/rubocop.yml
|
6
|
-
|
7
|
-
Lint/UnusedMethodArgument:
|
8
|
-
Exclude:
|
9
|
-
- 'lib/trailblazer/option.rb'
|
10
|
-
|
11
|
-
Metrics/ClassLength:
|
12
|
-
Exclude:
|
13
|
-
- 'test/**'
|
14
|
-
|
15
|
-
Style/ImplicitRuntimeError:
|
16
|
-
Exclude:
|
17
|
-
- 'lib/trailblazer/option.rb'
|
18
|
-
|
19
|
-
Naming/UncommunicativeMethodParamName:
|
20
|
-
Exclude:
|
21
|
-
- 'test/option_test.rb'
|
22
|
-
|
23
|
-
Style/ClassAndModuleChildren:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
# wants to use map instead of collect
|
27
|
-
Style/CollectionMethods:
|
28
|
-
Enabled: false
|
29
|
-
|
30
|
-
# wants to use fail instea of raise
|
31
|
-
Style/SignalException:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
# because in gemspec we say >= 2.0.0 wants to have 2.0 as target ruby version here but
|
35
|
-
# it's not supported anymore from rubocop
|
36
|
-
Gemspec/RequiredRubyVersion:
|
37
|
-
Enabled: false
|
38
|
-
|
39
|
-
Style/Lambda:
|
40
|
-
EnforcedStyle: literal
|