lab42_data_class 0.8.1 → 0.8.2

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: 6534869faa807d9d3f774d0fd1deef2d12d23475f06ab07208a46f7ef998056b
4
- data.tar.gz: f099a45edac8b2daf5d0637e7345ba3301c1ac379f2d0f4319b34172f847e431
3
+ metadata.gz: 7be679faed4f29c62488aceab84698e74d6d2e0fae75484e02455f5af8de2776
4
+ data.tar.gz: f8754463c2419091dfdcca58c29c2cc04a828a3b82e08ad9379ccf9a54357cd3
5
5
  SHA512:
6
- metadata.gz: 005cd3a1d4a52bfabaa371fb36769bce9530ed061d331f0009d39342a5af70c9126373eda6164471c0a58a14e27039261568439d40742b35b18e426b1fa61733
7
- data.tar.gz: ed3c5a31cc163448ba912e76284946c0f4ed47bd7b2ee3841e7e5918ad350f5763656da819bea96826da614285de7b981092ae4ee924dce574e638dd684919af
6
+ metadata.gz: 74673122bfc71202fc07f9f193e233972516d6a1d98c0170613bb7c5288d2e318a21fb2e5c45e477e62a6c47cbdc6bc596f6c5743553f4d73fd1cf58c0af4960
7
+ data.tar.gz: 6c41a6118819b88f66422ff5ed4f72cd9d561b655cc1e2d860fee9bc6eba913571814279ea163c223009bb7cb511d3e76f43aef15b2e0cb7cef5a1c706a12fe1
@@ -7,8 +7,12 @@ module Lab42
7
7
  class Constraint
8
8
  attr_reader :name, :function
9
9
 
10
- def call(value) = function.(value)
10
+ def call(value)
11
+ function.(value)
12
+ end
13
+
11
14
  def setter_constraint? = false
15
+ def to_proc = function
12
16
  def to_s = "Constraint<#{name}>"
13
17
 
14
18
  private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "lab42/data_class/constraints/constraint"
3
+ require_relative "../../constraints/constraint"
4
4
  module Lab42
5
5
  module DataClass
6
6
  class Proxy
@@ -5,9 +5,9 @@ module Lab42
5
5
  module DataClass
6
6
  class Proxy
7
7
  module Constraints
8
- def check_constraints_against_defaults(constraints)
8
+ def check_constraints_against_defaults
9
9
  errors = constraints
10
- .map(&_check_constraint_against_default)
10
+ .flat_map(&_check_constraint_against_default)
11
11
  .compact
12
12
  raise ConstraintError, errors.join("\n\n") unless errors.empty?
13
13
  end
@@ -19,7 +19,7 @@ module Lab42
19
19
  "constraints cannot be defined for undefined attributes #{errors.inspect}"
20
20
  end
21
21
 
22
- check_constraints_against_defaults(constraints)
22
+ check_constraints_against_defaults
23
23
  end
24
24
 
25
25
  private
@@ -32,9 +32,11 @@ module Lab42
32
32
  end
33
33
  end
34
34
 
35
- def _check_constraint_against_default_value(attr, value, constraint)
36
- unless Maker.make_constraint(constraint).(value)
37
- "default value #{value.inspect} is not allowed for attribute #{attr.inspect}"
35
+ def _check_constraint_against_default_value(attr, value, constraints)
36
+ constraints.map do |constraint|
37
+ unless constraint.(value)
38
+ "default value #{value.inspect} is not allowed for attribute #{attr.inspect}"
39
+ end
38
40
  end
39
41
  rescue StandardError => e
40
42
  "constraint error during validation of default value of attribute #{attr.inspect}\n #{e.message}"
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  module DataClass
5
- VERSION = "0.8.1"
5
+ VERSION = "0.8.2"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_data_class
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober