power_enum 0.9.4 → 0.10.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.
data/README.markdown CHANGED
@@ -293,6 +293,12 @@ As of version 0.8.0, you can pass in multiple arguments to `[]`. This returns a
293
293
  passed in values. Duplicates are filtered out. For example `BookingStatus[arg1, arg2, arg3]` would be equivalent to
294
294
  `[BookingStatus[arg1], BookingStatus[arg2], BookingStatus[arg3]]`.
295
295
 
296
+ ##### contains?(arg) (since version 0.10.0)
297
+
298
+ `BookingStatus.contains?(arg)` returns `true if` the given Symbol, String or id has a member instance in the enumeration,
299
+ `false` otherwise. Returns `true` if the argument is an enum instance, returns `false` if the argument is `nil` or any
300
+ other value.
301
+
296
302
  ##### all
297
303
 
298
304
  `BookingStatus.all` returns an array of all BookingStatus records that match the `:conditions` specified in
@@ -138,13 +138,13 @@ module PowerEnum::Enumerated
138
138
  # Returns all the active enum values. See the 'active?' instance method.
139
139
  def active
140
140
  return @all_active if @all_active
141
- @all_active = all.select{ |enum| enum.active? }.freeze
141
+ @all_active = all.find_all{ |enum| enum.active? }.freeze
142
142
  end
143
143
 
144
144
  # Returns all the inactive enum values. See the 'inactive?' instance method.
145
145
  def inactive
146
146
  return @all_inactive if @all_inactive
147
- @all_inactive = all.select{ |enum| !enum.active? }.freeze
147
+ @all_inactive = all.find_all{ |enum| !enum.active? }.freeze
148
148
  end
149
149
 
150
150
  # Returns the names of all the enum values as an array of symbols.
@@ -153,7 +153,8 @@ module PowerEnum::Enumerated
153
153
  end
154
154
 
155
155
  # Enum lookup by Symbol, String, or id. Returns <tt>arg<tt> if arg is
156
- # an enum instance. Passing in a list of arguments returns a list of enums.
156
+ # an enum instance. Passing in a list of arguments returns a list of
157
+ # enums. When called with no arguments, returns nil.
157
158
  def [](*args)
158
159
  case args.size
159
160
  when 0
@@ -181,6 +182,25 @@ module PowerEnum::Enumerated
181
182
  end
182
183
  end
183
184
 
185
+ # Returns <tt>true</tt> if the given Symbol, String or id has a member
186
+ # instance in the enumeration, <tt>false</tt> otherwise. Returns <tt>true</tt>
187
+ # if the argument is an enum instance, returns <tt>false</tt> if the argument
188
+ # is nil or any other value.
189
+ def contains?(arg)
190
+ case arg
191
+ when Symbol
192
+ !!lookup_name(arg.id2name)
193
+ when String
194
+ !!lookup_name(arg)
195
+ when Fixnum
196
+ !!lookup_id(arg)
197
+ when self
198
+ true
199
+ else
200
+ false
201
+ end
202
+ end
203
+
184
204
  # Deals with a lookup failure for the given argument.
185
205
  def handle_lookup_failure(arg)
186
206
  if (lookup_failure_handler = self.acts_enumerated_on_lookup_failure)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-11-17 00:00:00.000000000 Z
15
+ date: 2012-12-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: 2627295504409005826
148
+ hash: -1561438891797770640
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements: