blood_contracts-core 0.4.0 → 0.4.1
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/blood_contracts-core.gemspec +1 -1
- data/lib/blood_contracts/core/anything.rb +0 -1
- data/lib/blood_contracts/core/pipe.rb +3 -2
- data/lib/blood_contracts/core/refined.rb +2 -2
- data/lib/blood_contracts/core/sum.rb +4 -4
- data/lib/blood_contracts/core/tuple.rb +2 -3
- data/lib/blood_contracts/core/tuple_contract_failure.rb +1 -1
- data/spec/blood_contracts/core_spec.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f3ff63364178ca281b22b2ca291904ce9a70ec47056a41f9a622dd9a00c9a55
|
4
|
+
data.tar.gz: b5b000306c85eb7871fb3f4ad1c7a96d4fd8dbc8ceeab98bab49f50a78f611b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d84a0a438d5d264240e40ef8ba79f2732bcfa3f81d11533e9131b175887197c87e0ed84931126cf7aaa897c6fc7b68b7c0b17fc5ea49c03a383fec86ada6c658
|
7
|
+
data.tar.gz: 614ed9eb7021fc53fc0e55384868599afcfefb84437cf52a6739cb84e615bc929a3e5ad15ead259629820b32627d2641ae0f6738e33dda05ba8aa6d6cc94a864
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [0.4.1] - [2019-07-04]
|
9
|
+
|
10
|
+
Fixes:
|
11
|
+
|
12
|
+
Replaces the default context object in BC::Refined with simple Hash. No need to have default value for the context
|
13
|
+
key elements. It violates principlke of least surprise.
|
14
|
+
|
8
15
|
## [0.4.0] - [2019-06-25]
|
9
16
|
|
10
17
|
This is a first public release marked in change log with features extracted from production app.
|
@@ -21,7 +21,7 @@ module BloodContracts::Core
|
|
21
21
|
names ||= []
|
22
22
|
|
23
23
|
raise ArgumentError unless args.all? { |type| type < Refined }
|
24
|
-
pipe = Class.new(
|
24
|
+
pipe = Class.new(self) { def inspect; super; end }
|
25
25
|
finalize!(pipe, args, names)
|
26
26
|
pipe.class_eval(&block) if block_given?
|
27
27
|
pipe
|
@@ -35,7 +35,7 @@ module BloodContracts::Core
|
|
35
35
|
# rubocop:disable Style/CaseEquality
|
36
36
|
def and_then(other_type, **kwargs)
|
37
37
|
raise ArgumentError unless Class === other_type
|
38
|
-
pipe = Class.new(
|
38
|
+
pipe = Class.new(self) { def inspect; super; end }
|
39
39
|
finalize!(pipe, [self, other_type], kwargs[:names].to_a)
|
40
40
|
pipe
|
41
41
|
end
|
@@ -80,6 +80,7 @@ module BloodContracts::Core
|
|
80
80
|
def initialize(*)
|
81
81
|
super
|
82
82
|
@context[:steps] = @context[:steps].to_a
|
83
|
+
@context[:steps_values] = {}
|
83
84
|
end
|
84
85
|
|
85
86
|
# The type which is the result of data matching process
|
@@ -73,7 +73,7 @@ module BloodContracts::Core
|
|
73
73
|
# @param [Object] value that Refined holds and should match
|
74
74
|
# @option [Hash<Symbol, Object>] context to share between types
|
75
75
|
#
|
76
|
-
def initialize(value, context:
|
76
|
+
def initialize(value, context: {}, **)
|
77
77
|
@errors = []
|
78
78
|
@context = context
|
79
79
|
@value = value
|
@@ -84,7 +84,7 @@ module BloodContracts::Core
|
|
84
84
|
# @return [BC::Refined]
|
85
85
|
#
|
86
86
|
protected def match
|
87
|
-
|
87
|
+
raise NotImplementedError
|
88
88
|
end
|
89
89
|
alias call match
|
90
90
|
|
@@ -23,7 +23,7 @@ module BloodContracts::Core
|
|
23
23
|
type.respond_to?(:sum_of) ? acc + type.sum_of.to_a : acc << type
|
24
24
|
end
|
25
25
|
|
26
|
-
sum = Class.new(
|
26
|
+
sum = Class.new(self) { def inspect; super; end }
|
27
27
|
finalize!(sum, new_sum)
|
28
28
|
sum
|
29
29
|
end
|
@@ -35,7 +35,7 @@ module BloodContracts::Core
|
|
35
35
|
# @return [BC::Sum]
|
36
36
|
#
|
37
37
|
def or_a(other_type)
|
38
|
-
sum = Class.new(
|
38
|
+
sum = Class.new(self) { def inspect; super; end }
|
39
39
|
new_sum = sum_of.to_a
|
40
40
|
if other_type.respond_to?(:sum_of)
|
41
41
|
new_sum += other_type.sum_of.to_a
|
@@ -71,11 +71,11 @@ module BloodContracts::Core
|
|
71
71
|
# @return [BC::Refined]
|
72
72
|
#
|
73
73
|
def match
|
74
|
-
or_matches = self.class.sum_of.map do |type|
|
74
|
+
@or_matches = self.class.sum_of.map do |type|
|
75
75
|
type.match(@value, context: @context)
|
76
76
|
end
|
77
77
|
|
78
|
-
if (match = or_matches.find(&:valid?))
|
78
|
+
if (match = @or_matches.find(&:valid?))
|
79
79
|
match
|
80
80
|
else
|
81
81
|
failure(:no_matches)
|
@@ -24,7 +24,7 @@ module BloodContracts::Core
|
|
24
24
|
names = args.pop.delete(:names) if args.last.is_a?(Hash)
|
25
25
|
|
26
26
|
raise ArgumentError unless args.all? { |type| type < Refined }
|
27
|
-
tuple = Class.new(
|
27
|
+
tuple = Class.new(self) { def inspect; super; end }
|
28
28
|
tuple.instance_variable_set(:@attributes, args)
|
29
29
|
tuple.instance_variable_set(:@names, names.to_a)
|
30
30
|
tuple.instance_variable_set(:@finalized, true)
|
@@ -58,7 +58,6 @@ module BloodContracts::Core
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
61
|
# List of values in Tuple
|
63
62
|
#
|
64
63
|
# @return [Array<Object>]
|
@@ -70,7 +69,7 @@ module BloodContracts::Core
|
|
70
69
|
# @param [Array<Object>] *values that we'll keep inside the Tuple
|
71
70
|
# @option [Hash<Symbol, Object>] context to share between types
|
72
71
|
#
|
73
|
-
def initialize(*values, context:
|
72
|
+
def initialize(*values, context: {}, **)
|
74
73
|
@context = context
|
75
74
|
@context[:attributes] ||= {}
|
76
75
|
|
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.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Dolganov (sclinede)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|