trailblazer-context 0.1.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,186 @@
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
+ describe "positional and kws" do
12
+ class Step
13
+ def with_positional_and_keywords(options, a: nil, **more_options, &block)
14
+ [options, a, more_options, block]
15
+ end
16
+ end
17
+
18
+ WITH_POSITIONAL_AND_KEYWORDS = ->(options, a: nil, **more_options, &block) do
19
+ [options, a, more_options, block]
20
+ end
21
+
22
+ class WithPositionalAndKeywords
23
+ def self.call(options, a: nil, **more_options, &block)
24
+ [options, a, more_options, block]
25
+ end
26
+ end
27
+
28
+ let(:positional) { {a: 1} }
29
+ let(:keywords) { {a: 2, b: 3} }
30
+
31
+ let(:block) { ->(*) { snippet } }
32
+
33
+ describe ":method" do
34
+ let(:option) { Trailblazer::Option(:with_positional_and_keywords) }
35
+
36
+ it "passes through all args" do
37
+ step = Step.new
38
+
39
+ # positional = { a: 1 }
40
+ # keywords = { a: 2, b: 3 }
41
+ assert_result option.(positional, keywords, exec_context: step)
42
+ end
43
+
44
+ it "allows passing a block, too" do
45
+ step = Step.new
46
+
47
+ assert_result option.(positional, keywords, {exec_context: step}, &block), block
48
+ end
49
+ end
50
+
51
+ describe "lambda" do
52
+ let(:option) { Trailblazer::Option(WITH_POSITIONAL_AND_KEYWORDS) }
53
+
54
+ it "-> {} lambda" do
55
+ assert_result option.(positional, keywords, {})
56
+ end
57
+
58
+ it "allows passing a block, too" do
59
+ assert_result option.(positional, keywords, {}, &block), block
60
+ end
61
+
62
+ it "doesn't mind :exec_context" do
63
+ assert_result option.(positional, keywords, exec_context: "bogus")
64
+ end
65
+ end
66
+
67
+ describe "Callable" do
68
+ let(:option) { Trailblazer::Option(WithPositionalAndKeywords) }
69
+
70
+ it "passes through all args" do
71
+ assert_result option.(positional, keywords, exec_context: nil)
72
+ end
73
+
74
+ it "allows passing a block, too" do
75
+ assert_result option.(positional, keywords, {exec_context: nil}, &block), block
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "positionals" do
81
+ def assert_result_pos(result)
82
+ _(result).must_equal([1, 2, [3, 4]])
83
+ _(positionals).must_equal [1, 2, 3, 4]
84
+ end
85
+
86
+ class Step
87
+ def with_positionals(a, b, *args)
88
+ [a, b, args]
89
+ end
90
+ end
91
+
92
+ WITH_POSITIONALS = ->(a, b, *args) do
93
+ [a, b, args]
94
+ end
95
+
96
+ class WithPositionals
97
+ def self.call(a, b, *args)
98
+ [a, b, args]
99
+ end
100
+ end
101
+
102
+ let(:positionals) { [1, 2, 3, 4] }
103
+
104
+ it ":method" do
105
+ step = Step.new
106
+
107
+ option = Trailblazer::Option(:with_positionals)
108
+
109
+ assert_result_pos option.(*positionals, exec_context: step)
110
+ end
111
+
112
+ it "-> {} lambda" do
113
+ option = Trailblazer::Option(WITH_POSITIONALS)
114
+
115
+ assert_result_pos option.(*positionals, exec_context: "something")
116
+ end
117
+
118
+ it "callable" do
119
+ option = Trailblazer::Option(WithPositionals)
120
+
121
+ assert_result_pos option.(*positionals, exec_context: "something")
122
+ end
123
+ end
124
+
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
+ end
@@ -0,0 +1,3 @@
1
+ require "trailblazer-context"
2
+
3
+ require "minitest/autorun"
@@ -1,6 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'trailblazer/context/version'
3
+ require "trailblazer/context/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "trailblazer-context"
@@ -8,21 +8,24 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Nick Sutterer"]
9
9
  spec.email = ["apotonick@gmail.com"]
10
10
 
11
- spec.summary = %q{Argument-specific data structures for Trailblazer.}
12
- spec.description = %q{Argument-specific data structures for Trailblazer such as Context, Option and ContainerChain.}
11
+ spec.summary = "Argument-specific data structures for Trailblazer."
12
+ spec.description = "Argument-specific data structures for Trailblazer such as Context, Option and ContainerChain."
13
13
  spec.homepage = "http://trailblazer.to/gems/workflow"
14
14
  spec.licenses = ["MIT"]
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
17
+ f.match(%r(^test/))
18
18
  end
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.test_files = `git ls-files -z test`.split("\x0")
20
+
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.14"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "minitest", "~> 5.0"
23
+ spec.add_dependency "hashie", "~> 4.1"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "rake"
26
28
 
27
- spec.required_ruby_version = '>= 2.0.0'
29
+ # maybe we could remove this?
30
+ spec.required_ruby_version = ">= 2.1.0"
28
31
  end
metadata CHANGED
@@ -1,57 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-context
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-26 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: hashie
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
20
- type: :development
19
+ version: '4.1'
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: '1.14'
26
+ version: '4.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '5.0'
68
+ version: '0'
55
69
  description: Argument-specific data structures for Trailblazer such as Context, Option
56
70
  and ContainerChain.
57
71
  email:
@@ -61,6 +75,7 @@ extensions: []
61
75
  extra_rdoc_files: []
62
76
  files:
63
77
  - ".gitignore"
78
+ - ".travis.yml"
64
79
  - CHANGES.md
65
80
  - Gemfile
66
81
  - LICENSE
@@ -69,8 +84,17 @@ files:
69
84
  - lib/trailblazer-context.rb
70
85
  - lib/trailblazer/container_chain.rb
71
86
  - lib/trailblazer/context.rb
87
+ - lib/trailblazer/context/container.rb
88
+ - lib/trailblazer/context/container/with_aliases.rb
89
+ - lib/trailblazer/context/store/indifferent_access.rb
72
90
  - lib/trailblazer/context/version.rb
73
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
95
+ - test/context_test.rb
96
+ - test/option_test.rb
97
+ - test/test_helper.rb
74
98
  - trailblazer-context.gemspec
75
99
  homepage: http://trailblazer.to/gems/workflow
76
100
  licenses:
@@ -84,16 +108,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
108
  requirements:
85
109
  - - ">="
86
110
  - !ruby/object:Gem::Version
87
- version: 2.0.0
111
+ version: 2.1.0
88
112
  required_rubygems_version: !ruby/object:Gem::Requirement
89
113
  requirements:
90
114
  - - ">="
91
115
  - !ruby/object:Gem::Version
92
116
  version: '0'
93
117
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.8
118
+ rubygems_version: 3.0.8
96
119
  signing_key:
97
120
  specification_version: 4
98
121
  summary: Argument-specific data structures for Trailblazer.
99
- test_files: []
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
126
+ - test/context_test.rb
127
+ - test/option_test.rb
128
+ - test/test_helper.rb