active_enum 1.0.0.rc6 → 1.0.0
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 +4 -4
- data/README.rdoc +1 -1
- data/lib/active_enum/base.rb +7 -7
- data/lib/active_enum/extensions.rb +4 -4
- data/lib/active_enum/version.rb +1 -1
- data/spec/active_enum/extensions_spec.rb +5 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4dd61a23068e97e9582ac6bb9109414172733ae0c26759177ecab8082819cd6
|
4
|
+
data.tar.gz: bab417444c404468c0fea123e31a05ef392bf0a14b32ccefa84fa9d2f63129d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5383983a54ff4169f5cbefe0a4907c9007144808a322e0eb31fd4e0ba52e86e2a814d7f8c6dedac24ce9127a56db556878f337ce437175cfe43f111e65bc81d
|
7
|
+
data.tar.gz: 9ba6f7231906b870a9f9832ab477a658a99e5df227fcde6fcff47e47ba86533bf7f182147befd6295b00de285a6248f70d53fa803cb48617cbc71eb68e767f23
|
data/README.rdoc
CHANGED
data/lib/active_enum/base.rb
CHANGED
@@ -76,7 +76,7 @@ module ActiveEnum
|
|
76
76
|
alias_method :[], :get
|
77
77
|
|
78
78
|
def include?(value)
|
79
|
-
!
|
79
|
+
!get_value(value, false).nil?
|
80
80
|
end
|
81
81
|
|
82
82
|
# Access any meta data defined for a given id or name. Returns a hash.
|
@@ -88,22 +88,22 @@ module ActiveEnum
|
|
88
88
|
private
|
89
89
|
|
90
90
|
# Access value row array for a given id or name value.
|
91
|
-
def get_value(index)
|
91
|
+
def get_value(index, raise_on_not_found = ActiveEnum.raise_on_not_found)
|
92
92
|
if index.is_a?(Integer)
|
93
93
|
store.get_by_id(index)
|
94
94
|
else
|
95
95
|
store.get_by_name(index)
|
96
|
-
end || (
|
96
|
+
end || (raise_on_not_found ? raise(ActiveEnum::NotFound, "#{self} value for '#{index}' was not found") : nil)
|
97
97
|
end
|
98
98
|
|
99
99
|
def id_and_name_and_meta(hash)
|
100
100
|
if hash.has_key?(:name)
|
101
|
-
id = hash.
|
102
|
-
name = hash.
|
103
|
-
meta = hash
|
101
|
+
id = hash.fetch(:id) { next_id }
|
102
|
+
name = hash.fetch(:name).freeze
|
103
|
+
meta = hash.except(:id, :name).freeze
|
104
104
|
return id, name, (meta.empty? ? nil : meta)
|
105
105
|
elsif hash.keys.first.is_a?(Integer)
|
106
|
-
return *Array(hash).first
|
106
|
+
return *Array(hash).first.tap { |arr| arr[1].freeze }
|
107
107
|
else
|
108
108
|
raise ActiveEnum::InvalidValue, "The value supplied, #{hash}, is not a valid format."
|
109
109
|
end
|
@@ -92,9 +92,9 @@ module ActiveEnum
|
|
92
92
|
when :id
|
93
93
|
value if enum[value]
|
94
94
|
when :name
|
95
|
-
enum[value]
|
95
|
+
enum[value].dup
|
96
96
|
when Symbol
|
97
|
-
(enum.meta(value) || {})[arg]
|
97
|
+
(enum.meta(value) || {})[arg].try(:dup)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
DEF
|
@@ -110,7 +110,7 @@ module ActiveEnum
|
|
110
110
|
class_eval <<-DEF
|
111
111
|
def #{attribute}=(arg)
|
112
112
|
if arg.is_a?(Symbol)
|
113
|
-
super
|
113
|
+
super(self.class.active_enum_for(:#{attribute})[arg])
|
114
114
|
else
|
115
115
|
super
|
116
116
|
end
|
@@ -127,7 +127,7 @@ module ActiveEnum
|
|
127
127
|
class_eval <<-DEF
|
128
128
|
def #{attribute}?(arg=nil)
|
129
129
|
if arg
|
130
|
-
self.#{attribute}(:id) == self.class.active_enum_for(:#{attribute})[arg]
|
130
|
+
self.#{attribute}(:id).present? && self.#{attribute}(:id) == self.class.active_enum_for(:#{attribute})[arg]
|
131
131
|
else
|
132
132
|
super()
|
133
133
|
end
|
data/lib/active_enum/version.rb
CHANGED
@@ -176,6 +176,11 @@ describe ActiveEnum::Extensions do
|
|
176
176
|
expect(person.sex?(:female)).to be_falsey
|
177
177
|
expect(person.sex?(:Female)).to be_falsey
|
178
178
|
end
|
179
|
+
|
180
|
+
it 'should return false if attribute is nil regardless of enum value' do
|
181
|
+
person.sex = nil
|
182
|
+
expect(person.sex?(:nonexistent)).to be_falsey
|
183
|
+
end
|
179
184
|
end
|
180
185
|
|
181
186
|
context "with value as enum name symbol" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -83,11 +83,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - "
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: '0'
|
89
89
|
requirements: []
|
90
|
-
rubygems_version: 3.0.3
|
90
|
+
rubygems_version: 3.0.3.1
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Define enum classes in Rails and use them to enumerate ActiveRecord attributes
|