linearly 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/linearly/errors/broken_contract.rb +16 -3
- data/lib/linearly/flow.rb +2 -2
- data/lib/linearly/runner.rb +2 -2
- data/lib/linearly/validation.rb +10 -4
- data/lib/linearly/version.rb +1 -1
- data/spec/errors/broken_contract_spec.rb +7 -3
- data/spec/validation_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50a3c517f78d9e37fad6f7fbf445cc5d3569244b85163e2a1974e7d247c957ba
|
4
|
+
data.tar.gz: cf2e7d85b851095308eced41285adcc3ae9c86786d1338d7b80052511ac2e9e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a8f5d4f0bd5304e53fdc41558b6ce9c3722d342706a2d312aab8293cd40eb999248adff0fc7d1f5934620c4232d2e79f02aa62344c43745c366cf916246e1d1
|
7
|
+
data.tar.gz: 3f625d7a397cb45021381d9e3413a031989d0a1d4311fab12a3f9047d10c7281b1b2ac69a11bb45a15d194029fc64ad833a280b8f4917d5646b570411d152798
|
@@ -36,18 +36,31 @@ module Linearly
|
|
36
36
|
|
37
37
|
# Constructor for a {BrokenContract} error
|
38
38
|
#
|
39
|
+
# @param source [Object]
|
39
40
|
# @param failures [Hash<Symbol, Validation::Failure>]
|
40
41
|
#
|
41
42
|
# @api public
|
42
43
|
# @example
|
43
44
|
# Linearly::Errors::BrokenContract::Inputs.new(
|
45
|
+
# Steps::HelloWorld,
|
44
46
|
# key: Linearly::Validation::Failure::Missing.instance,
|
45
47
|
# )
|
46
48
|
# => #<Linearly::Errors::BrokenContract::Inputs:
|
47
|
-
# failed input expectations: [key]>
|
48
|
-
def initialize(failures)
|
49
|
+
# failed input expectations on Steps::HelloWorld: [key]>
|
50
|
+
def initialize(source, failures)
|
51
|
+
@source = source
|
49
52
|
@failures = failures
|
50
|
-
super("#{copy}: [#{keys.join(', ')}]")
|
53
|
+
super("#{copy} on #{source_string}: [#{keys.join(', ')}]")
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# Stringify the source to put it in the error message
|
59
|
+
#
|
60
|
+
# @return [String]
|
61
|
+
# @api private
|
62
|
+
def source_string
|
63
|
+
@source.is_a?(Class) ? @source.name : @source.class.name
|
51
64
|
end
|
52
65
|
|
53
66
|
# {Inputs} means a {BrokenContract} on inputs.
|
data/lib/linearly/flow.rb
CHANGED
@@ -79,9 +79,9 @@ module Linearly
|
|
79
79
|
# @api private
|
80
80
|
def steps
|
81
81
|
[
|
82
|
-
Validation::Inputs.new(inputs),
|
82
|
+
Validation::Inputs.new(self, inputs),
|
83
83
|
*@steps.map(&Runner.method(:new)),
|
84
|
-
Validation::Outputs.new(outputs),
|
84
|
+
Validation::Outputs.new(self, outputs),
|
85
85
|
]
|
86
86
|
end
|
87
87
|
|
data/lib/linearly/runner.rb
CHANGED
@@ -28,9 +28,9 @@ module Linearly
|
|
28
28
|
# @api private
|
29
29
|
def steps
|
30
30
|
[
|
31
|
-
Validation::Inputs.new(step.inputs),
|
31
|
+
Validation::Inputs.new(step, step.inputs),
|
32
32
|
step,
|
33
|
-
Validation::Outputs.new(step.outputs),
|
33
|
+
Validation::Outputs.new(step, step.outputs),
|
34
34
|
]
|
35
35
|
end
|
36
36
|
end
|
data/lib/linearly/validation.rb
CHANGED
@@ -7,13 +7,16 @@ module Linearly
|
|
7
7
|
class Validation
|
8
8
|
# Constructor for a {Validation}
|
9
9
|
#
|
10
|
+
# @param source [Object] source of the validation, to be passed to errors
|
11
|
+
# for better messaging.
|
10
12
|
# @param expectations [Hash<Symbol, Expectation>] a hash of per-field
|
11
13
|
# expectations. An expectation can be +true+ (just checking for field
|
12
14
|
# presence), a class name (checking for value type) or a +Proc+
|
13
15
|
# taking a value and returning a +Boolean+.
|
14
16
|
#
|
15
17
|
# @api private
|
16
|
-
def initialize(expectations)
|
18
|
+
def initialize(source, expectations)
|
19
|
+
@source = source
|
17
20
|
@expectations =
|
18
21
|
expectations
|
19
22
|
.map { |key, expectation| [key, Expectation.to_proc(expectation)] }
|
@@ -28,7 +31,7 @@ module Linearly
|
|
28
31
|
# @api private
|
29
32
|
def call(state)
|
30
33
|
Validator
|
31
|
-
.new(expectations, state)
|
34
|
+
.new(@source, expectations, state)
|
32
35
|
.validate(error_class)
|
33
36
|
end
|
34
37
|
|
@@ -70,11 +73,14 @@ module Linearly
|
|
70
73
|
class Validator
|
71
74
|
# Constructor method for a {Validator}
|
72
75
|
#
|
76
|
+
# @param source [Object] source of the validation, to be passed to errors
|
77
|
+
# for better messaging.
|
73
78
|
# @param expectations [Hash<Symbol, Expectation>]
|
74
79
|
# @param state [Statefully::State]
|
75
80
|
#
|
76
81
|
# @api private
|
77
|
-
def initialize(expectations, state)
|
82
|
+
def initialize(source, expectations, state)
|
83
|
+
@source = source
|
78
84
|
@expectations = expectations
|
79
85
|
@state = state
|
80
86
|
end
|
@@ -88,7 +94,7 @@ module Linearly
|
|
88
94
|
def validate(error_class)
|
89
95
|
failures = invalid.merge(missing).freeze
|
90
96
|
return @state if failures.empty?
|
91
|
-
@state.fail(error_class.new(failures))
|
97
|
+
@state.fail(error_class.new(@source, failures))
|
92
98
|
end
|
93
99
|
|
94
100
|
private
|
data/lib/linearly/version.rb
CHANGED
@@ -9,17 +9,21 @@ module Linearly
|
|
9
9
|
unexpected: Validation::Failure::Unexpected.instance,
|
10
10
|
}
|
11
11
|
end
|
12
|
-
let(:error) { described_class.new(failures) }
|
12
|
+
let(:error) { described_class.new('string', failures) }
|
13
13
|
|
14
14
|
describe BrokenContract::Inputs do
|
15
|
-
let(:message)
|
15
|
+
let(:message) do
|
16
|
+
'failed input expectations on String: [missing, unexpected]'
|
17
|
+
end
|
16
18
|
|
17
19
|
it { expect(error.message).to eq message }
|
18
20
|
it { expect(error.failures).to eq failures }
|
19
21
|
end
|
20
22
|
|
21
23
|
describe BrokenContract::Outputs do
|
22
|
-
let(:message)
|
24
|
+
let(:message) do
|
25
|
+
'failed output expectations on String: [missing, unexpected]'
|
26
|
+
end
|
23
27
|
|
24
28
|
it { expect(error.message).to eq message }
|
25
29
|
it { expect(error.failures).to eq failures }
|
data/spec/validation_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Linearly
|
4
4
|
describe Validation do
|
5
|
-
let(:validation) { described_class.new(expectations).call(state) }
|
5
|
+
let(:validation) { described_class.new('string', expectations).call(state) }
|
6
6
|
let(:state) { Statefully::State.create(key: 'val') }
|
7
7
|
|
8
8
|
shared_examples 'validation_fails' do |error_class|
|