attribool 2.0.1 → 2.0.2

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: f70889d0edf2407bfaee163da31ab791d35bea5921024e54fbab658792c81d46
4
- data.tar.gz: 0ed3735087e12402627c1773564efa42e2710696d9e932dcd5073a369cf0f6d8
3
+ metadata.gz: d928a7ac0b90deb248cfcbb3a9b638baa6a38a8c62691c884df1e2db2f7c6d04
4
+ data.tar.gz: 525256019fd56a8bc53695c1772e6367fcb6dac0ac05da4a4f457431029d21d9
5
5
  SHA512:
6
- metadata.gz: df790e07a5164be0da050dce51747bfa73a5884637304854706ffc5948347fc4faf3cb300a8cef35849b3ad65f145813ee8dc3a98fde5234fb8fb0fd7c493a36
7
- data.tar.gz: b6740fa6386e012e9a39040abde54e9e091f194ac3c1b7bc1a4127d72cd4eff829b27d76a1ee1c34e507330dfcb0804555d7aba98980608851b7e4ccf6522f88
6
+ metadata.gz: 3719316d9feaa069f64748a23ef1ba9531dbecb6b7cb3188e8292f9f70a7cdd3a262522b63a8a6c7b9673a232a3c6e2dc86953cba6527ea6c9727d5e32360c0f
7
+ data.tar.gz: 792822e7f8e5ee0242d8a60cd5ab0870613794a26652bcb7025dbdda5dd3500bee8004c66fdd297c8e0a26c0e6ec1a458967e69186a91a1795bb5ee92e65a4d6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attribool (2.0.1)
4
+ attribool (2.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -8,13 +8,24 @@ module Attribool
8
8
  include Enumerable
9
9
 
10
10
  ##
11
- # Generate the list.
11
+ # Create an +AttributeList+ from a list of attribute names.
12
12
  #
13
- # @param [String, Symbol] *attributes
13
+ # @param [String, Symbol] *attribute_names
14
14
  #
15
15
  # @kwarg [nil, String, Symbol, Proc] method_name
16
- def initialize(*attributes, method_name: nil)
17
- @entries = attributes.map { |a| Attribool::Attribute.new(a, method_name) }
16
+ #
17
+ # @return [AttributeList]
18
+ def self.build(*attribute_names, method_name: nil)
19
+ new(*attribute_names.map { |a| Attribool::Attribute.new(a, method_name) })
20
+ end
21
+
22
+ ##
23
+ # Construct the list.
24
+ #
25
+ # @param [String, Symbol] *attributes
26
+ def initialize(*attributes)
27
+ ValidatorService.call(:attribute_list, *attributes)
28
+ @entries = attributes
18
29
  end
19
30
 
20
31
  ##
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Attribool::Validators
4
+ class AttributeListValidator
5
+ def initialize(*items)
6
+ @items = items
7
+ end
8
+
9
+ def valid?
10
+ @items.all?(Attribool::Attribute)
11
+ end
12
+
13
+ def error
14
+ TypeError.new("All items must be an instance of Attribool::Attribute")
15
+ end
16
+ end
17
+ end
@@ -21,7 +21,7 @@ module Attribool
21
21
  # Patch version.
22
22
  #
23
23
  # @return [Integer]
24
- PATCH = 1
24
+ PATCH = 2
25
25
 
26
26
  module_function
27
27
 
data/lib/attribool.rb CHANGED
@@ -10,6 +10,7 @@ require_relative "attribool/validators/condition_validator"
10
10
  require_relative "attribool/validators/method_name_validator"
11
11
  require_relative "attribool/validators/nil_attribute_validator"
12
12
  require_relative "attribool/validators/strict_boolean_validator"
13
+ require_relative "attribool/validators/attribute_list_validator"
13
14
 
14
15
  ##
15
16
  # Adds macros for dealing with boolean attributes.
@@ -44,7 +45,7 @@ module Attribool
44
45
  def bool_reader(*attributes, allow_nil: true, method_name: nil, condition: nil)
45
46
  ValidatorService.call(:method_name, method_name, attributes.size)
46
47
 
47
- AttributeList.new(*attributes, method_name: method_name).each do |attribute|
48
+ AttributeList.build(*attributes, method_name: method_name).each do |attribute|
48
49
  define_method(attribute.reader) do
49
50
  instance_variable_get(attribute.ivar).then do |value|
50
51
  ValidatorService.call(:nil_attribute, attribute.ivar, value, allow_nil)
@@ -63,7 +64,7 @@ module Attribool
63
64
  #
64
65
  # @kwarg [Boolean] strict
65
66
  def bool_writer(*attributes, strict: false)
66
- AttributeList.new(*attributes).each do |attribute|
67
+ AttributeList.build(*attributes).each do |attribute|
67
68
  define_method(attribute.writer) do |value|
68
69
  ValidatorService.call(:strict_boolean, value, strict)
69
70
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribool
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Gray
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-26 00:00:00.000000000 Z
11
+ date: 2023-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -111,6 +111,7 @@ files:
111
111
  - lib/attribool/attribute_list.rb
112
112
  - lib/attribool/reader_name.rb
113
113
  - lib/attribool/validator_service.rb
114
+ - lib/attribool/validators/attribute_list_validator.rb
114
115
  - lib/attribool/validators/condition_validator.rb
115
116
  - lib/attribool/validators/method_name_validator.rb
116
117
  - lib/attribool/validators/nil_attribute_validator.rb