power_enum 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -133,7 +133,7 @@ It's easier to use the `references` method if you intend to stick to the default
133
133
 
134
134
  There are two methods added to Rails migrations:
135
135
 
136
- ##### `create_enum(enum_name, options = {}, &block)`
136
+ ##### create_enum(enum\_name, options = {}, &block)
137
137
 
138
138
  Creates a new enum table. `enum_name` will be automatically pluralized. The following options are supported:
139
139
 
@@ -192,7 +192,7 @@ is the equivalent of
192
192
 
193
193
  Notice that a unique index is automatically created on the specified name column.
194
194
 
195
- ##### `remove_enum(enum_name)`
195
+ ##### remove\_enum(enum\_name)
196
196
 
197
197
  Drops the enum table. `enum_name` will be automatically pluralized.
198
198
 
@@ -217,11 +217,12 @@ With that, your BookingStatus class will have the following methods defined:
217
217
 
218
218
  #### Class Methods
219
219
 
220
- ##### `[](arg)`
220
+ ##### [](arg)
221
221
 
222
222
  `BookingStatus[arg]` performs a lookup for the BookingStatus instance for the given arg. The arg value can be a 'string' or a :symbol,
223
223
  in which case the lookup will be against the BookingStatus.name field. Alternatively arg can be a Fixnum,
224
- in which case the lookup will be against the BookingStatus.id field.
224
+ in which case the lookup will be against the BookingStatus.id field. Since version 0.5.3, it returns the arg
225
+ if arg is an instance of the enum (in this case BookingStatus) as a convenience.
225
226
 
226
227
  The `:on_lookup_failure` option specifies the name of a *class* method to invoke when the `[]` method is unable to locate a BookingStatus record for arg.
227
228
  The default is the built-in `:enforce_none` which returns nil. There are also built-ins for `:enforce_strict` (raise and exception regardless of the type for arg),
@@ -231,15 +232,15 @@ and `:enforce_strict_symbols` (raises an exception if the arg is a Symbol).
231
232
  The purpose of the `:on_lookup_failure` option is that a) under some circumstances a lookup failure is a Bad Thing and action should be taken,
232
233
  therefore b) a fallback action should be easily configurable.
233
234
 
234
- ##### `all`
235
+ ##### all
235
236
 
236
237
  `BookingStatus.all` returns an array of all BookingStatus records that match the `:conditions` specified in `acts_as_enumerated`, in the order specified by `:order`.
237
238
 
238
- ##### `active`
239
+ ##### active
239
240
 
240
241
  `BookingStatus.active` returns an array of all BookingStatus records that are marked active. See the `active?` instance method.
241
242
 
242
- ##### `inactive`
243
+ ##### inactive
243
244
 
244
245
  `BookingStatus.inactive` returns an array of all BookingStatus records that are inactive. See the `inactive?` instance method.
245
246
 
@@ -247,7 +248,7 @@ therefore b) a fallback action should be easily configurable.
247
248
 
248
249
  Each enumeration model gets the following instance methods.
249
250
 
250
- ##### `===(arg)`
251
+ ##### ===(arg)
251
252
 
252
253
  Behavior depends on the type of `arg`.
253
254
 
@@ -268,7 +269,7 @@ You should note that defining an `:on_lookup_failure` method that raises an exce
268
269
 
269
270
  `like?` is aliased to `===`
270
271
 
271
- ##### `in?(*list)`
272
+ ##### in?(*list)
272
273
 
273
274
  Returns true if any element in the list returns true for `===(arg)`, false otherwise.
274
275
 
@@ -276,21 +277,21 @@ Example:
276
277
 
277
278
  BookingStatus[:foo].in? :foo, :bar, :baz #Returns true
278
279
 
279
- ##### `name`
280
+ ##### name
280
281
 
281
282
  Returns the 'name' of the enum, i.e. the value in the `:name_column` attribute of the enumeration model.
282
283
 
283
- ##### `name_sym`
284
+ ##### name\_sym
284
285
 
285
286
  Returns the symbol representation of the name of the enum. `BookingStatus[:foo].name_sym` returns :foo.
286
287
 
287
- ##### `active?`
288
+ ##### active?
288
289
 
289
290
  Returns true if the instance is active, false otherwise. If it has an attribute 'active',
290
291
  returns the attribute cast to a boolean, otherwise returns true. This method is used by the `active`
291
292
  class method to select active enums.
292
293
 
293
- ##### `inactive?`
294
+ ##### inactive?
294
295
 
295
296
  Returns true if the instance is inactive, false otherwise. Default implementations returns `!active?`
296
297
  This method is used by the `inactive` class method to select inactive enums.
@@ -336,11 +337,11 @@ attribute unless a non-nil value has already been set.
336
337
 
337
338
  With that, your Booking class will have the following methods defined:
338
339
 
339
- #### `status`
340
+ #### status
340
341
 
341
342
  Returns the BookingStatus with an id that matches the value in the Booking.status_id.
342
343
 
343
- #### `status=(arg)`
344
+ #### status=(arg)
344
345
 
345
346
  Sets the value for Booking.status_id using the id of the BookingStatus instance passed as an argument. As a
346
347
  short-hand, you can also pass it the 'name' of a BookingStatus instance, either as a 'string' or :symbol, or pass in the id directly.
@@ -373,11 +374,11 @@ for all has\_enumerated fields if you happen to have more than one defined in yo
373
374
  NOTE: A `nil` is always considered to be a valid value for `status=(arg)` since it's assumed you're trying to null out the foreign key.
374
375
  The `:on_lookup_failure` will be bypassed.
375
376
 
376
- #### `has_enumerated?(attr)`
377
+ #### has\_enumerated?(attr)
377
378
 
378
379
  Returns true if the given attr is an enumerated attributes, false otherwise. `attr` can be a string or a symbol.
379
380
 
380
- #### `enumerated_attributes`
381
+ #### enumerated\_attributes
381
382
 
382
383
  Returns an array of attributes which are enumerated.
383
384
 
@@ -66,7 +66,8 @@ module ActiveRecord
66
66
  @all_inactive = all.select{ |enum| !enum.active? }.freeze
67
67
  end
68
68
 
69
- # Enum lookup by Symbol, String, or id.
69
+ # Enum lookup by Symbol, String, or id. Returns <tt>arg<tt> if arg is
70
+ # an enum instance.
70
71
  def [](arg)
71
72
  case arg
72
73
  when Symbol
@@ -75,6 +76,8 @@ module ActiveRecord
75
76
  return_val = lookup_name(arg) and return return_val
76
77
  when Fixnum
77
78
  return_val = lookup_id(arg) and return return_val
79
+ when self
80
+ return arg
78
81
  when nil
79
82
  nil
80
83
  else
metadata CHANGED
@@ -1,15 +1,10 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: power_enum
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 2
10
- version: 0.5.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Trevor Squires
14
9
  - Pivotal Labs
15
10
  - Arthur Shagall
@@ -17,98 +12,82 @@ authors:
17
12
  autorequire:
18
13
  bindir: bin
19
14
  cert_chain: []
20
-
21
- date: 2012-01-07 00:00:00 Z
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
24
- requirement: &id001 !ruby/object:Gem::Requirement
15
+ date: 2012-01-17 00:00:00.000000000Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rails
19
+ requirement: &26849560 !ruby/object:Gem::Requirement
25
20
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
34
24
  version: 3.0.0
35
- version_requirements: *id001
36
- name: rails
37
- prerelease: false
38
25
  type: :runtime
39
- - !ruby/object:Gem::Dependency
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
49
- version_requirements: *id002
50
- name: jeweler
51
26
  prerelease: false
52
- type: :development
53
- - !ruby/object:Gem::Dependency
54
- requirement: &id003 !ruby/object:Gem::Requirement
27
+ version_requirements: *26849560
28
+ - !ruby/object:Gem::Dependency
29
+ name: jeweler
30
+ requirement: &26848800 !ruby/object:Gem::Requirement
55
31
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
63
- version_requirements: *id003
64
- name: rspec
65
- prerelease: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
66
36
  type: :development
67
- - !ruby/object:Gem::Dependency
68
- requirement: &id004 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ version_requirements: *26848800
39
+ - !ruby/object:Gem::Dependency
40
+ name: rspec
41
+ requirement: &26848100 !ruby/object:Gem::Requirement
69
42
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
77
- version_requirements: *id004
78
- name: sqlite3
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
79
48
  prerelease: false
49
+ version_requirements: *26848100
50
+ - !ruby/object:Gem::Dependency
51
+ name: sqlite3
52
+ requirement: &26847160 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
80
58
  type: :development
81
- - !ruby/object:Gem::Dependency
82
- requirement: &id005 !ruby/object:Gem::Requirement
59
+ prerelease: false
60
+ version_requirements: *26847160
61
+ - !ruby/object:Gem::Dependency
62
+ name: genspec
63
+ requirement: &26846180 !ruby/object:Gem::Requirement
83
64
  none: false
84
- requirements:
85
- - - "="
86
- - !ruby/object:Gem::Version
87
- hash: 21
88
- segments:
89
- - 0
90
- - 2
91
- - 1
65
+ requirements:
66
+ - - =
67
+ - !ruby/object:Gem::Version
92
68
  version: 0.2.1
93
- version_requirements: *id005
94
- name: genspec
95
- prerelease: false
96
69
  type: :development
97
- description: |
98
- Power Enum allows you to treat instances of your ActiveRecord models as though they were an enumeration of values.
99
- It allows you to cleanly solve many of the problems that the traditional Rails alternatives handle poorly if at all.
100
- It is particularly suitable for scenarios where your Rails application is not the only user of the database, such as
101
- when it's used for analytics or reporting.
70
+ prerelease: false
71
+ version_requirements: *26846180
72
+ description: ! 'Power Enum allows you to treat instances of your ActiveRecord models
73
+ as though they were an enumeration of values.
74
+
75
+ It allows you to cleanly solve many of the problems that the traditional Rails alternatives
76
+ handle poorly if at all.
77
+
78
+ It is particularly suitable for scenarios where your Rails application is not the
79
+ only user of the database, such as
102
80
 
81
+ when it''s used for analytics or reporting.
82
+
83
+ '
103
84
  email: arthur.shagall@gmail.com
104
85
  executables: []
105
-
106
86
  extensions: []
107
-
108
- extra_rdoc_files:
87
+ extra_rdoc_files:
109
88
  - LICENSE
110
89
  - README.md
111
- files:
90
+ files:
112
91
  - examples/virtual_enumerations_sample.rb
113
92
  - lib/active_record/acts/enumerated.rb
114
93
  - lib/active_record/aggregations/has_enumerated.rb
@@ -126,36 +105,27 @@ files:
126
105
  - README.md
127
106
  homepage: http://github.com/albertosaurus/enumerations_mixin
128
107
  licenses: []
129
-
130
108
  post_install_message:
131
109
  rdoc_options: []
132
-
133
- require_paths:
110
+ require_paths:
134
111
  - lib
135
- required_ruby_version: !ruby/object:Gem::Requirement
112
+ required_ruby_version: !ruby/object:Gem::Requirement
136
113
  none: false
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
142
- - 0
143
- version: "0"
144
- required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
119
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
151
- - 0
152
- version: "0"
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
153
124
  requirements: []
154
-
155
125
  rubyforge_project:
156
126
  rubygems_version: 1.8.10
157
127
  signing_key:
158
128
  specification_version: 3
159
- summary: Allows you to treat instances of your ActiveRecord models as though they were an enumeration of values
129
+ summary: Allows you to treat instances of your ActiveRecord models as though they
130
+ were an enumeration of values
160
131
  test_files: []
161
-