attribool 1.0.2 → 1.0.3
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.rb +19 -9
- data/lib/attribool/version.rb +1 -1
- data/lib/attribool.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6bff0b78f856fe87c3d101b3f2eaf4eeeb49fcc9d5a7171857df555ec93125
|
4
|
+
data.tar.gz: fcf0a984bd435bd05c0b6039201419fb5aa3c40df94efb33e288d1ff069ca57d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47e07045578ba1f698eebdcfc72d9d0de7d634f2d8950b7067bb6c4c74baabbbadf90e92e4392872c8992c09e2954833daae5b8a496f7d01efc7e2537e8f392b
|
7
|
+
data.tar.gz: 70cf40cf0102b2def2b68b9c5b51103bbad23ebd9a8a01d812f6a41a766ae3fd007455ed4842f5000298d147ded173b09fd1d3b6bf6ecedf8b7ad6fd9b9f6ae2
|
data/Gemfile.lock
CHANGED
data/lib/attribool/attribute.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
# Abstraction for an attribute to determine its name, reader, writer, and
|
3
5
|
# instance variable name.
|
@@ -26,17 +28,25 @@ class Attribool::Attribute
|
|
26
28
|
# @return [String]
|
27
29
|
attr_reader :writer
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
class << self
|
32
|
+
##
|
33
|
+
# Ensures that if multiple attributes are being defined, and +method_name+
|
34
|
+
# is provided, that +method_name+ is a +Proc+.
|
35
|
+
#
|
36
|
+
# @param [Integer] number_of_attributes
|
37
|
+
#
|
38
|
+
# @param [String, Symbol, Proc] method_name
|
39
|
+
def validate_method_name(method_name, number_of_attributes)
|
40
|
+
return if number_of_attributes == 1 || nil_or_proc?(method_name)
|
41
|
+
|
38
42
|
raise ArgumentError, "Must use a Proc when creating multiple methods"
|
39
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def nil_or_proc?(method_name) # :nodoc:
|
48
|
+
method_name.nil? || (method_name.is_a?(Proc) && method_name.arity == 1)
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
52
|
##
|
data/lib/attribool/version.rb
CHANGED
data/lib/attribool.rb
CHANGED
@@ -23,7 +23,7 @@ module Attribool
|
|
23
23
|
condition: nil,
|
24
24
|
method_name: nil
|
25
25
|
)
|
26
|
-
Attribute.validate_method_name(attributes.size
|
26
|
+
Attribute.validate_method_name(method_name, attributes.size)
|
27
27
|
|
28
28
|
attributes.map { |a| Attribute.new(a, method_name) }.each do |attribute|
|
29
29
|
define_method(attribute.reader) do
|
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: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Gray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|