teckel 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.
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Teckel::Chain do
4
+ module TeckelChainNoneInputTest
5
+ class MyOperation
6
+ include Teckel::Operation
7
+ result!
8
+
9
+ settings Struct.new(:say)
10
+
11
+ input none
12
+ output String
13
+ error none
14
+
15
+ def call(_)
16
+ settings&.say || "Called"
17
+ end
18
+ end
19
+
20
+ class Chain
21
+ include Teckel::Chain
22
+
23
+ step :a, MyOperation
24
+ end
25
+ end
26
+
27
+ specify "call chain without input value" do
28
+ result = TeckelChainNoneInputTest::Chain.call
29
+ expect(result.success).to eq("Called")
30
+ end
31
+
32
+ specify "call chain runner without input value" do
33
+ result = TeckelChainNoneInputTest::Chain.with(a: "What").call
34
+ expect(result.success).to eq("What")
35
+ end
36
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Teckel::Operation do
4
+ context "default settings" do
5
+ module TeckelOperationDefaultSettings
6
+ class BaseOperation
7
+ include ::Teckel::Operation
8
+
9
+ input none
10
+ output Symbol
11
+ error none
12
+
13
+ def call(_input)
14
+ success! settings.injected
15
+ end
16
+ end
17
+ end
18
+
19
+ shared_examples "operation with default settings" do |operation|
20
+ subject { operation }
21
+
22
+ it "with no settings" do
23
+ expect(subject.call).to eq(:default_value)
24
+ end
25
+
26
+ it "with settings" do
27
+ expect(subject.with(:injected_value).call).to eq(:injected_value)
28
+ end
29
+ end
30
+
31
+ describe "with default constructor and clever Settings class" do
32
+ it_behaves_like(
33
+ "operation with default settings",
34
+ Class.new(TeckelOperationDefaultSettings::BaseOperation) do
35
+ settings(Class.new do
36
+ def initialize(injected = nil)
37
+ @injected = injected
38
+ end
39
+
40
+ def injected
41
+ @injected || :default_value
42
+ end
43
+
44
+ class << self
45
+ alias :[] :new # make us respond to the default constructor
46
+ end
47
+ end)
48
+
49
+ default_settings!
50
+ end
51
+ )
52
+ end
53
+
54
+ describe "with custom constructor and clever Settings class" do
55
+ it_behaves_like(
56
+ "operation with default settings",
57
+ Class.new(TeckelOperationDefaultSettings::BaseOperation) do
58
+ settings(Class.new do
59
+ def initialize(injected = nil)
60
+ @injected = injected
61
+ end
62
+
63
+ def injected
64
+ @injected || :default_value
65
+ end
66
+ end)
67
+
68
+ settings_constructor :new
69
+ default_settings!
70
+ end
71
+ )
72
+ end
73
+
74
+ describe "with default constructor and simple Settings class" do
75
+ it_behaves_like(
76
+ "operation with default settings",
77
+ Class.new(TeckelOperationDefaultSettings::BaseOperation) do
78
+ settings Struct.new(:injected)
79
+
80
+ default_settings! -> { settings.new(:default_value) }
81
+ end
82
+ )
83
+
84
+ it_behaves_like(
85
+ "operation with default settings",
86
+ Class.new(TeckelOperationDefaultSettings::BaseOperation) do
87
+ settings Struct.new(:injected)
88
+
89
+ default_settings!(:default_value)
90
+ end
91
+ )
92
+ end
93
+ end
94
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teckel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Schulze
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2020-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,22 +95,27 @@ files:
95
95
  - README.md
96
96
  - lib/teckel.rb
97
97
  - lib/teckel/chain.rb
98
+ - lib/teckel/chain/config.rb
98
99
  - lib/teckel/chain/result.rb
99
100
  - lib/teckel/chain/runner.rb
100
101
  - lib/teckel/chain/step.rb
101
102
  - lib/teckel/config.rb
102
103
  - lib/teckel/contracts.rb
103
104
  - lib/teckel/operation.rb
105
+ - lib/teckel/operation/config.rb
104
106
  - lib/teckel/operation/result.rb
105
107
  - lib/teckel/operation/runner.rb
106
108
  - lib/teckel/result.rb
107
109
  - lib/teckel/version.rb
110
+ - spec/chain/default_settings_spec.rb
108
111
  - spec/chain/inheritance_spec.rb
112
+ - spec/chain/none_input_spec.rb
109
113
  - spec/chain/results_spec.rb
110
114
  - spec/chain_around_hook_spec.rb
111
115
  - spec/chain_spec.rb
112
116
  - spec/config_spec.rb
113
117
  - spec/doctest_helper.rb
118
+ - spec/operation/default_settings_spec.rb
114
119
  - spec/operation/inheritance_spec.rb
115
120
  - spec/operation/result_spec.rb
116
121
  - spec/operation/results_spec.rb
@@ -129,7 +134,7 @@ metadata:
129
134
  changelog_uri: https://github.com/github.com/fnordfish/blob/master/CHANGELOG.md
130
135
  source_code_uri: https://github.com/github.com/fnordfish
131
136
  bug_tracker_uri: https://github.com/github.com/fnordfish/issues
132
- documentation_uri: https://www.rubydoc.info/gems/teckel/0.4.0
137
+ documentation_uri: https://www.rubydoc.info/gems/teckel/0.5.0
133
138
  post_install_message:
134
139
  rdoc_options: []
135
140
  require_paths:
@@ -150,12 +155,15 @@ signing_key:
150
155
  specification_version: 4
151
156
  summary: Operations with enforced in/out/err data structures
152
157
  test_files:
158
+ - spec/chain/default_settings_spec.rb
153
159
  - spec/chain/inheritance_spec.rb
160
+ - spec/chain/none_input_spec.rb
154
161
  - spec/chain/results_spec.rb
155
162
  - spec/chain_around_hook_spec.rb
156
163
  - spec/chain_spec.rb
157
164
  - spec/config_spec.rb
158
165
  - spec/doctest_helper.rb
166
+ - spec/operation/default_settings_spec.rb
159
167
  - spec/operation/inheritance_spec.rb
160
168
  - spec/operation/result_spec.rb
161
169
  - spec/operation/results_spec.rb