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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6fb4a88a4e4c0b8894a94b35dee75c23f9ddbdba0db2c5078dd51049cbeb82a
4
- data.tar.gz: 53e5d91603101b6c0e6590ceb58f6c214cbd221be7da6e4780825b51e71b640f
3
+ metadata.gz: a4dd61a23068e97e9582ac6bb9109414172733ae0c26759177ecab8082819cd6
4
+ data.tar.gz: bab417444c404468c0fea123e31a05ef392bf0a14b32ccefa84fa9d2f63129d1
5
5
  SHA512:
6
- metadata.gz: b208b4ad29373d4f604673eef17315d5ede6265384d0cb3cadda81b674953fa35d09ac8149a2831a257d2f4e05e9931b02c01767aece9b2a7e45e4152f09e462
7
- data.tar.gz: 8ef7bde84f962ac14307dccfee60849d022699c2841fabd7fe33cb5b4c284cafcff938e91497a6f44f02df27fc0cd0d7bbf707162b16663df30ad61d63688f08
6
+ metadata.gz: c5383983a54ff4169f5cbefe0a4907c9007144808a322e0eb31fd4e0ba52e86e2a814d7f8c6dedac24ce9127a56db556878f337ce437175cfe43f111e65bc81d
7
+ data.tar.gz: 9ba6f7231906b870a9f9832ab477a658a99e5df227fcde6fcff47e47ba86533bf7f182147befd6295b00de285a6248f70d53fa803cb48617cbc71eb68e767f23
data/README.rdoc CHANGED
@@ -15,7 +15,7 @@ From gem version 1.0 onwards this plugin will only have Rails 4+ support. If you
15
15
 
16
16
  Put this in your Gemfile
17
17
 
18
- gem 'active_enum', '~> 1.0.0.rc4'
18
+ gem 'active_enum', '~> 1.0.0'
19
19
 
20
20
  Then generate the config initializer file
21
21
 
@@ -76,7 +76,7 @@ module ActiveEnum
76
76
  alias_method :[], :get
77
77
 
78
78
  def include?(value)
79
- !get(value).nil?
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 || (ActiveEnum.raise_on_not_found ? raise(ActiveEnum::NotFound, "#{self} value for '#{index}' was not found") : nil)
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.delete(:id) || next_id
102
- name = hash.delete(:name)
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 self.class.active_enum_for(:#{attribute})[arg]
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
@@ -1,3 +1,3 @@
1
1
  module ActiveEnum
2
- VERSION = '1.0.0.rc6'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -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.rc6
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: 2020-07-01 00:00:00.000000000 Z
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: 1.3.1
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