blood_contracts-core 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0eafc70e494dca609f476b8d8d910d34d7be58c1699bec33f139b1c6ba85b69
4
- data.tar.gz: 6ef7c133021e3422c7e56a97e7e71e156cdb97cad8be67ce4da014013b302cf9
3
+ metadata.gz: 15d2c1262b54f96eb2eb15b4e342927fd45448781c0fca59a3ac76ace95a2409
4
+ data.tar.gz: d47507f3401dc9c956d4a1922693eab12a207bb3a3f67ea7b5de398b5e2d0246
5
5
  SHA512:
6
- metadata.gz: dd33b8390228963b54931953499796365b6056a289856f9e9a7d4a8a864f907a899c30af7d22f0feae141d01391409fc4c3f32917a8c12c5ba3ca27991b2da3e
7
- data.tar.gz: dd16faf2a2b9d28a1bdcdce86e3203a28b856e8b739e91639be7bbde8f0beadf7745bb390c0740af210e4d2e156d86d74ada387511cd3ed077828f23fe384ac6
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
- if args.last.is_a?(Hash)
10
- names = args.pop.delete(: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
- share_context_with(match) do |context|
49
- context[:steps][step_name(index)] = unpacked_value
50
- index += 1
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, context: @context, **kwargs)
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(
@@ -7,7 +7,7 @@ module BloodContracts
7
7
  attr_reader :sum_of, :finalized
8
8
 
9
9
  def new(*args)
10
- return super if finalized
10
+ return super(*args) if finalized
11
11
 
12
12
  new_sum = args.reduce([]) { |acc, type| type.respond_to?(:sum_of) ? acc + type.sum_of.to_a : acc << type }
13
13
 
@@ -1,5 +1,5 @@
1
1
  module BloodContracts
2
2
  module Core
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
5
5
  end
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.2
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-05-18 00:00:00.000000000 Z
11
+ date: 2019-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler