attribool 1.0.2 → 1.0.3

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: 40de41768cc69a7a822e65934217e6695907f8e2aa0896cac72073d4d7ee8620
4
- data.tar.gz: 26bcc326d49235611dda2d00a230c592c192a502c4f2215698931ce76a0af80f
3
+ metadata.gz: eb6bff0b78f856fe87c3d101b3f2eaf4eeeb49fcc9d5a7171857df555ec93125
4
+ data.tar.gz: fcf0a984bd435bd05c0b6039201419fb5aa3c40df94efb33e288d1ff069ca57d
5
5
  SHA512:
6
- metadata.gz: f236b203d01b2f4a916c2f96c3ecc61f04d361b406700e93997fb17f5d965fd04f550858fc65ea33e5345247c3d36651bcd04a13faf454259f474743e0232c7b
7
- data.tar.gz: 0bd9e8337766c2c4b9bae8a9e32cb70b898c6bdd6826b042c72a6938344840754c07af30a5737007f2c317ccbc1b8f326e1fe7af04e2982dad5fbdcd21e99ccc
6
+ metadata.gz: 47e07045578ba1f698eebdcfc72d9d0de7d634f2d8950b7067bb6c4c74baabbbadf90e92e4392872c8992c09e2954833daae5b8a496f7d01efc7e2537e8f392b
7
+ data.tar.gz: 70cf40cf0102b2def2b68b9c5b51103bbad23ebd9a8a01d812f6a41a766ae3fd007455ed4842f5000298d147ded173b09fd1d3b6bf6ecedf8b7ad6fd9b9f6ae2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attribool (1.0.2)
4
+ attribool (1.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- # Ensures that if multiple attributes are being defined, and +method_name+ is
31
- # provided, that +method_name+ is a +Proc+.
32
- #
33
- # @param [Integer] number_of_attributes
34
- #
35
- # @param [String, Symbol, Proc] method_name
36
- def self.validate_method_name(number_of_attributes, method_name)
37
- if number_of_attributes > 1 && method_name && !method_name.is_a?(Proc)
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
  ##
@@ -21,7 +21,7 @@ module Attribool
21
21
  # Patch version.
22
22
  #
23
23
  # @return [Integer]
24
- PATCH = 2
24
+ PATCH = 3
25
25
 
26
26
  ##
27
27
  # Version as +[MAJOR, MINOR, PATCH]+
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, method_name)
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.2
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-27 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake