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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/attribool/attribute_list.rb +15 -4
- data/lib/attribool/validators/attribute_list_validator.rb +17 -0
- data/lib/attribool/version.rb +1 -1
- data/lib/attribool.rb +3 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d928a7ac0b90deb248cfcbb3a9b638baa6a38a8c62691c884df1e2db2f7c6d04
|
4
|
+
data.tar.gz: 525256019fd56a8bc53695c1772e6367fcb6dac0ac05da4a4f457431029d21d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3719316d9feaa069f64748a23ef1ba9531dbecb6b7cb3188e8292f9f70a7cdd3a262522b63a8a6c7b9673a232a3c6e2dc86953cba6527ea6c9727d5e32360c0f
|
7
|
+
data.tar.gz: 792822e7f8e5ee0242d8a60cd5ab0870613794a26652bcb7025dbdda5dd3500bee8004c66fdd297c8e0a26c0e6ec1a458967e69186a91a1795bb5ee92e65a4d6
|
data/Gemfile.lock
CHANGED
@@ -8,13 +8,24 @@ module Attribool
|
|
8
8
|
include Enumerable
|
9
9
|
|
10
10
|
##
|
11
|
-
#
|
11
|
+
# Create an +AttributeList+ from a list of attribute names.
|
12
12
|
#
|
13
|
-
# @param [String, Symbol] *
|
13
|
+
# @param [String, Symbol] *attribute_names
|
14
14
|
#
|
15
15
|
# @kwarg [nil, String, Symbol, Proc] method_name
|
16
|
-
|
17
|
-
|
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
|
data/lib/attribool/version.rb
CHANGED
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.
|
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.
|
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.
|
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-
|
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
|