lab42_data_class 0.7.0 → 0.7.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: 2ae30c490e9b798403214f49c4cbc43564bf47b741878f9aa174e27dc17a85b8
4
- data.tar.gz: 2e7ab04142e8eb38206ba14bd03464465844b307087708d382e253fc40dd8f1b
3
+ metadata.gz: 8fdfa61b721a7e006b42dd59c3dc61c4f3442faaa0d50feeaa5ed4b20ea5838c
4
+ data.tar.gz: fa5d7ab0e6133c398caaaa1762e75a5820123e67088acc4750c36e9246ff2dc0
5
5
  SHA512:
6
- metadata.gz: f40faa136f73115809cea4f73d722188ea62e9299319313b1ffcbcc852c710de0c399c3d1c54dcdb1ae1de57173baabfb66607f636ff62b747f133774e4c205a
7
- data.tar.gz: 294c975087b12a3cab2731eb78840d735dbdeac923f1c2edb8d5beaf598848caf18d571e3129b42dac0ad2d276657507f4df10268a41863ffb2150ea11df5d8a
6
+ metadata.gz: 53af67931648a621cd0ff18912ce191dc2d0a005eacfd4df741bbdf8a58a9c695e168055129c76be08efcb4810d3910a5df362512996c8d2375da6ff17b61be8
7
+ data.tar.gz: c65a655f447f154b1a4e7584393fe3058403ef53cf5651a51fd39e5af7ebbd88768e90dc9b8d1a7d582316a35d2786abff6c6a04cc2f445f8d725657773c9a21
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
 
2
-
3
2
  [![Issue Count](https://codeclimate.com/github/RobertDober/lab42_data_class/badges/issue_count.svg)](https://codeclimate.com/github/RobertDober/lab42_data_class)
4
3
  [![CI](https://github.com/robertdober/lab42_data_class/workflows/CI/badge.svg)](https://github.com/robertdober/lab42_data_class/actions)
5
4
  [![Coverage Status](https://coveralls.io/repos/github/RobertDober/lab42_data_class/badge.svg?branch=main)](https://coveralls.io/github/RobertDober/lab42_data_class?branch=main)
@@ -9,7 +8,6 @@
9
8
 
10
9
  # Lab42::DataClass
11
10
 
12
-
13
11
  An Immutable DataClass for Ruby
14
12
 
15
13
  Exposes a class factory function `Kernel::DataClass` and a module `Lab42::DataClass` which can
@@ -41,7 +39,7 @@ Therefore we can summarise the features (or not so features, that is for you to
41
39
  ## Usage
42
40
 
43
41
  ```sh
44
- gem install lab42_data_class
42
+ gem install lab42_data_class
45
43
  ```
46
44
 
47
45
  With bundler
@@ -14,7 +14,7 @@ module Lab42
14
14
 
15
15
  def define_constraint
16
16
  ->((attr, constraint)) do
17
- if members.member?(attr)
17
+ if members!.member?(attr)
18
18
  constraints[attr] << Maker.make_constraint(constraint)
19
19
  nil
20
20
  else
@@ -26,7 +26,7 @@ module Lab42
26
26
  def define_constraints(constraints)
27
27
  errors = constraints.map(&define_constraint).compact
28
28
  unless errors.empty?
29
- raise ArgumentError,
29
+ raise UndefinedAttributeError,
30
30
  "constraints cannot be defined for undefined attributes #{errors.inspect}"
31
31
  end
32
32
 
@@ -26,6 +26,10 @@ module Lab42
26
26
  end
27
27
  end
28
28
 
29
+ def members!
30
+ @__members__ = Set.new(positionals + defaults.keys)
31
+ end
32
+
29
33
  def positionals
30
34
  @__positionals__ ||= []
31
35
  end
@@ -54,7 +54,7 @@ module Lab42
54
54
  positionals.delete(name)
55
55
  defaults.delete(name)
56
56
  derived_attributes.update(name => true) do |_key, _old,|
57
- raise DuplicateDefinitionError, "Redefinition of derived attribute #{name}"
57
+ raise DuplicateDefinitionError, "Redefinition of derived attribute #{name.inspect}"
58
58
  end
59
59
  klass.module_eval(&_define_derived_attribute(name, &blk))
60
60
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lab42
4
+ module DataClass
5
+ class UndefinedAttributeError < RuntimeError
6
+ end
7
+ end
8
+ end
9
+ # SPDX-License-Identifier: Apache-2.0
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  module DataClass
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.1"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
@@ -3,6 +3,7 @@
3
3
  require_relative './data_class/constraint_error'
4
4
  require_relative './data_class/duplicate_definition_error'
5
5
  require_relative './data_class/kernel'
6
+ require_relative './data_class/undefined_attribute_error'
6
7
  require_relative './data_class/validation_error'
7
8
  require_relative './data_class/proxy'
8
9
  require_relative './pair'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_data_class
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-27 00:00:00.000000000 Z
11
+ date: 2022-02-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  An Immutable DataClass for Ruby
@@ -34,6 +34,7 @@ files:
34
34
  - lib/lab42/data_class/proxy/memos.rb
35
35
  - lib/lab42/data_class/proxy/mixin.rb
36
36
  - lib/lab42/data_class/proxy/validations.rb
37
+ - lib/lab42/data_class/undefined_attribute_error.rb
37
38
  - lib/lab42/data_class/validation_error.rb
38
39
  - lib/lab42/data_class/version.rb
39
40
  - lib/lab42/eq_and_patterns.rb