blood_contracts-core 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15d2c1262b54f96eb2eb15b4e342927fd45448781c0fca59a3ac76ace95a2409
|
4
|
+
data.tar.gz: d47507f3401dc9c956d4a1922693eab12a207bb3a3f67ea7b5de398b5e2d0246
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6872bfc993b273b5d05713aa81f29c0a456cad1e8ebbbcd716055d04e15354c89c2fe7aba5d1a9bb2abbb165b82fc00e161b26c9437550e7a29581cba3ba62c7
|
7
|
+
data.tar.gz: a8ebbd47519ef4bb94e343e01bd9fcbefae0a3f05a140a6218c2848b340da8bd51537fadc61339bf248dda5b0478bb3a88f5d3fd98e63f06f390c80788508436
|
@@ -4,10 +4,10 @@ module BloodContracts
|
|
4
4
|
class << self
|
5
5
|
attr_reader :steps, :names, :finalized
|
6
6
|
|
7
|
-
def new(*args)
|
8
|
-
return super(*args) if finalized
|
9
|
-
|
10
|
-
names =
|
7
|
+
def new(*args, **kwargs)
|
8
|
+
return super(*args, **kwargs) if finalized
|
9
|
+
unless kwargs.empty?
|
10
|
+
names = kwargs.delete(:names)
|
11
11
|
end
|
12
12
|
names ||= []
|
13
13
|
|
@@ -38,17 +38,21 @@ module BloodContracts
|
|
38
38
|
attr_writer :names
|
39
39
|
end
|
40
40
|
|
41
|
+
def initialize(*)
|
42
|
+
super
|
43
|
+
@context[:types] = @context[:types].to_a
|
44
|
+
end
|
45
|
+
|
41
46
|
def match
|
42
47
|
super do
|
43
48
|
index = 0
|
44
49
|
self.class.steps.reduce(value) do |next_value, step|
|
45
50
|
unpacked_value = unpack_refined(next_value)
|
46
|
-
match = step.match(unpacked_value)
|
51
|
+
match = step.match(unpacked_value, context: @context)
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
53
|
+
@context[:steps][step_name(index)] = unpacked_value
|
54
|
+
types << match.class.name unless current_type.eql?(match.class.name)
|
55
|
+
index += 1
|
52
56
|
|
53
57
|
break match if match.invalid?
|
54
58
|
if block_given? && index < self.class.steps.size
|
@@ -63,6 +67,14 @@ module BloodContracts
|
|
63
67
|
match.errors
|
64
68
|
end
|
65
69
|
|
70
|
+
private def types
|
71
|
+
context[:types]
|
72
|
+
end
|
73
|
+
|
74
|
+
private def current_type
|
75
|
+
context[:types].last
|
76
|
+
end
|
77
|
+
|
66
78
|
private def step_name(index)
|
67
79
|
self.class.names[index] || index
|
68
80
|
end
|
@@ -13,11 +13,11 @@ module BloodContracts
|
|
13
13
|
end
|
14
14
|
alias :> :and_then
|
15
15
|
|
16
|
-
def match(*args)
|
16
|
+
def match(*args, **kwargs)
|
17
17
|
if block_given?
|
18
|
-
new(*args).match { |*subargs| yield(*subargs) }
|
18
|
+
new(*args, **kwargs).match { |*subargs| yield(*subargs) }
|
19
19
|
else
|
20
|
-
new(*args).match
|
20
|
+
new(*args, **kwargs).match
|
21
21
|
end
|
22
22
|
end
|
23
23
|
alias :call :match
|
@@ -70,7 +70,7 @@ module BloodContracts
|
|
70
70
|
unpack_refined @value
|
71
71
|
end
|
72
72
|
|
73
|
-
def failure(error = nil, errors: @errors,
|
73
|
+
def failure(error = nil, errors: @errors, **kwargs)
|
74
74
|
error ||= kwargs unless kwargs.empty?
|
75
75
|
errors << error if error
|
76
76
|
self.class.failure_klass.new(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blood_contracts-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Dolganov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin/
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|