blood_contracts-core 0.4.0 → 0.4.1

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: 7c89ea50c7af537eb81bfd8f949165ffaffde2bdeb9aec92668e601acc90802c
4
- data.tar.gz: 6c85bee20832ba39fc933987823b1dcbc7583ab0f991599837a2f0625d74d826
3
+ metadata.gz: 7f3ff63364178ca281b22b2ca291904ce9a70ec47056a41f9a622dd9a00c9a55
4
+ data.tar.gz: b5b000306c85eb7871fb3f4ad1c7a96d4fd8dbc8ceeab98bab49f50a78f611b0
5
5
  SHA512:
6
- metadata.gz: fe7e788aac1df68e58bd5e28f2dfcf875f5b47deca6b0012cd309b81749f147b712290608d513bf97421f5064813e3a44a14888d63c774ac8f01cfa0027c27c0
7
- data.tar.gz: 0a349cdc0f9f668fe7cda58a3531e322f6b76ee8116640ce4aad9e25d7ae58680f8a3c00cadc80c202b525974d6a66637b0c35ec5e7947a93d9e70bb375af061
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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "blood_contracts-core"
3
- gem.version = "0.4.0"
3
+ gem.version = "0.4.1"
4
4
  gem.authors = ["Sergey Dolganov (sclinede)"]
5
5
  gem.email = ["sclinede@evilmartians.com"]
6
6
 
@@ -1,7 +1,6 @@
1
1
  module BloodContracts::Core
2
2
  # Refinement type which represents data which is always correct
3
3
  class Anything < Refined
4
-
5
4
  # The type which is the result of data matching process
6
5
  # (for Anything is always self)
7
6
  #
@@ -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(Pipe) { def inspect; super; end }
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(Pipe) { def inspect; super; end }
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: Hash.new { |h, k| h[k] = {} }, **)
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
- fail NotImplementedError
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(Sum) { def inspect; super; end }
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(Sum) { def inspect; super; end }
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(Tuple) { def inspect; super; end }
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: Hash.new { |h, k| h[k] = {} }, **)
72
+ def initialize(*values, context: {}, **)
74
73
  @context = context
75
74
  @context[:attributes] ||= {}
76
75
 
@@ -1,5 +1,5 @@
1
1
  module BloodContracts::Core
2
- # Represents failure in during of Tuple data matching
2
+ # Represents failure in Tuple data matching
3
3
  class TupleContractFailure < ContractFailure
4
4
  # Hash of attributes (name & type pairs)
5
5
  #
@@ -1,4 +1,3 @@
1
-
2
1
  require "spec_helper"
3
2
 
4
3
  RSpec.describe BloodContracts::Core do
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.0
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-02 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler