power_enum 0.5.4 → 0.5.5
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.md +76 -53
- data/lib/active_record/acts/enumerated.rb +51 -10
- data/lib/active_record/aggregations/has_enumerated.rb +18 -8
- data/lib/generators/enum/enum_generator.rb +3 -0
- data/lib/power_enum/reflection.rb +3 -0
- metadata +77 -104
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Power Enum
|
2
2
|
|
3
|
+
https://github.com/albertosaurus/enumerations\_mixin
|
4
|
+
|
3
5
|
Enumerations for Rails 3.X Done Right.
|
4
6
|
|
5
7
|
## What is this?:
|
@@ -9,20 +11,24 @@ It allows you to cleanly solve many of the problems that the traditional Rails a
|
|
9
11
|
It is particularly suitable for scenarios where your Rails application is not the only user of the database, such as
|
10
12
|
when it's used for analytics or reporting.
|
11
13
|
|
12
|
-
Power Enum is
|
13
|
-
to the original plugin by Trevor Squires located at
|
14
|
-
it has been reworked and a full
|
14
|
+
Power Enum is a fork of the Rails 3 modernization made by the fine folks at Protocool
|
15
|
+
https://github.com/protocool/enumerations\_mixin to the original plugin by Trevor Squires located at
|
16
|
+
https://github.com/protocool/enumerations\_mixin. While many of the core ideas remain, it has been reworked and a full
|
17
|
+
test suite written to facilitate further development.
|
15
18
|
|
16
19
|
At it's most basic level, it allows you to say things along the lines of:
|
17
20
|
|
18
21
|
booking = Booking.new(:status => BookingStatus[:provisional])
|
19
22
|
booking.status = :confirmed
|
23
|
+
booking = Booking.create( :status => :rejected )
|
20
24
|
|
21
25
|
Booking.find :first,
|
22
26
|
:conditions => ['status_id = ?', BookingStatus[:provisional].id]
|
23
27
|
|
24
28
|
BookingStatus.all.collect {|status|, [status.name, status.id]}
|
25
29
|
|
30
|
+
Booking.with_status :provisional, :confirmed
|
31
|
+
|
26
32
|
See "How to use it" below for more information.
|
27
33
|
|
28
34
|
## Installation
|
@@ -50,10 +56,11 @@ are cached in memory. If the table has an 'active' column, the value of that at
|
|
50
56
|
will be used to determine which enum instances are active.
|
51
57
|
Otherwise, all values are considered active.
|
52
58
|
|
53
|
-
`has_enumerated` adds methods to your ActiveRecord model for setting and retrieving enumerated values using an
|
59
|
+
`has_enumerated` adds methods to your ActiveRecord model for setting and retrieving enumerated values using an
|
60
|
+
associated acts\_as\_enumerated model.
|
54
61
|
|
55
|
-
There is also an `ActiveRecord::VirtualEnumerations` helper module to create 'virtual' acts\_as\_enumerated models
|
56
|
-
cluttering up your models directory with acts\_as\_enumerated classes.
|
62
|
+
There is also an `ActiveRecord::VirtualEnumerations` helper module to create 'virtual' acts\_as\_enumerated models
|
63
|
+
which helps to avoid cluttering up your models directory with acts\_as\_enumerated classes.
|
57
64
|
|
58
65
|
## How to use it
|
59
66
|
|
@@ -79,7 +86,7 @@ from a pre-test Rake task.
|
|
79
86
|
|
80
87
|
### migration
|
81
88
|
|
82
|
-
If you're using Rails prior to 3.
|
89
|
+
If you're using Rails prior to 3.0, your migration file will look something like this:
|
83
90
|
|
84
91
|
class CreateEnumBookingStatus < ActiveRecord::Migration
|
85
92
|
|
@@ -133,7 +140,7 @@ It's easier to use the `references` method if you intend to stick to the default
|
|
133
140
|
|
134
141
|
There are two methods added to Rails migrations:
|
135
142
|
|
136
|
-
#####
|
143
|
+
##### create\_enum(enum\_name, options = {}, &block)
|
137
144
|
|
138
145
|
Creates a new enum table. `enum_name` will be automatically pluralized. The following options are supported:
|
139
146
|
|
@@ -208,7 +215,7 @@ is the equivalent of
|
|
208
215
|
|
209
216
|
class BookingStatus < ActiveRecord::Base
|
210
217
|
acts_as_enumerated :conditions => 'optional_sql_conditions',
|
211
|
-
:order => '
|
218
|
+
:order => 'optional_sql_order_by',
|
212
219
|
:on_lookup_failure => :optional_class_method,
|
213
220
|
:name_column => 'optional_name_column' #If required, may override the default name column
|
214
221
|
end
|
@@ -219,30 +226,35 @@ With that, your BookingStatus class will have the following methods defined:
|
|
219
226
|
|
220
227
|
##### [](arg)
|
221
228
|
|
222
|
-
`BookingStatus[arg]` performs a lookup for the BookingStatus instance for the given arg. The arg value can be a
|
223
|
-
in which case the lookup will be against the BookingStatus.name field. Alternatively arg can be
|
224
|
-
in which case the lookup will be against the BookingStatus.id field. Since version 0.5.3, it returns the arg
|
229
|
+
`BookingStatus[arg]` performs a lookup for the BookingStatus instance for the given arg. The arg value can be a
|
230
|
+
'string' or a :symbol, in which case the lookup will be against the BookingStatus.name field. Alternatively arg can be
|
231
|
+
a Fixnum, in which case the lookup will be against the BookingStatus.id field. Since version 0.5.3, it returns the arg
|
225
232
|
if arg is an instance of the enum (in this case BookingStatus) as a convenience.
|
226
233
|
|
227
|
-
The `:on_lookup_failure` option specifies the name of a *class* method to invoke when the `[]` method is unable to
|
228
|
-
The default is the built-in `:enforce_none` which returns nil. There are also
|
229
|
-
`:
|
230
|
-
|
234
|
+
The `:on_lookup_failure` option specifies the name of a *class* method to invoke when the `[]` method is unable to
|
235
|
+
locate a BookingStatus record for arg. The default is the built-in `:enforce_none` which returns nil. There are also
|
236
|
+
built-ins for `:enforce_strict` (raise and exception regardless of the type for arg), `:enforce_strict_literals` (raises
|
237
|
+
an exception if the arg is a Fixnum or Symbol), `:enforce_strict_ids` (raises and exception if the arg is a Fixnum) and
|
238
|
+
`:enforce_strict_symbols` (raises an exception if the arg is a Symbol).
|
231
239
|
|
232
|
-
The purpose of the `:on_lookup_failure` option is that a) under some circumstances a lookup failure is a Bad Thing and
|
240
|
+
The purpose of the `:on_lookup_failure` option is that a) under some circumstances a lookup failure is a Bad Thing and
|
241
|
+
action should be taken,
|
233
242
|
therefore b) a fallback action should be easily configurable.
|
234
243
|
|
235
244
|
##### all
|
236
245
|
|
237
|
-
`BookingStatus.all` returns an array of all BookingStatus records that match the `:conditions` specified in
|
246
|
+
`BookingStatus.all` returns an array of all BookingStatus records that match the `:conditions` specified in
|
247
|
+
`acts_as_enumerated`, in the order specified by `:order`.
|
238
248
|
|
239
249
|
##### active
|
240
250
|
|
241
|
-
`BookingStatus.active` returns an array of all BookingStatus records that are marked active. See the `active?` instance
|
251
|
+
`BookingStatus.active` returns an array of all BookingStatus records that are marked active. See the `active?` instance
|
252
|
+
method.
|
242
253
|
|
243
254
|
##### inactive
|
244
255
|
|
245
|
-
`BookingStatus.inactive` returns an array of all BookingStatus records that are inactive. See the `inactive?` instance
|
256
|
+
`BookingStatus.inactive` returns an array of all BookingStatus records that are inactive. See the `inactive?` instance
|
257
|
+
method.
|
246
258
|
|
247
259
|
#### Instance Methods
|
248
260
|
|
@@ -265,7 +277,8 @@ Examples:
|
|
265
277
|
BookingStatus[:foo] === [:foo, :bar, :baz] #Returns true
|
266
278
|
BookingStatus[:foo] === nil #Returns false
|
267
279
|
|
268
|
-
You should note that defining an `:on_lookup_failure` method that raises an exception will cause `===` to also raise an
|
280
|
+
You should note that defining an `:on_lookup_failure` method that raises an exception will cause `===` to also raise an
|
281
|
+
exception for any lookup failure of `BookingStatus[arg]`.
|
269
282
|
|
270
283
|
`like?` is aliased to `===`
|
271
284
|
|
@@ -298,11 +311,13 @@ This method is used by the `inactive` class method to select inactive enums.
|
|
298
311
|
|
299
312
|
#### Notes
|
300
313
|
|
301
|
-
`acts_as_enumerated` records are considered immutable. By default you cannot create/alter/destroy instances because they
|
302
|
-
Because of Rails' process-based model it is not safe to allow updating acts\_as\_enumerated
|
303
|
-
as of version 0.5.1, `to_s` is overriden to return the name of the
|
314
|
+
`acts_as_enumerated` records are considered immutable. By default you cannot create/alter/destroy instances because they
|
315
|
+
are cached in memory. Because of Rails' process-based model it is not safe to allow updating acts\_as\_enumerated
|
316
|
+
records as the caches will get out of sync. Also, as of version 0.5.1, `to_s` is overriden to return the name of the
|
317
|
+
enum instance.
|
304
318
|
|
305
|
-
However, one instance where updating the models *should* be allowed is if you are using seeds.rb to seed initial values
|
319
|
+
However, one instance where updating the models *should* be allowed is if you are using seeds.rb to seed initial values
|
320
|
+
into the database.
|
306
321
|
|
307
322
|
Using the above example you would do the following:
|
308
323
|
|
@@ -315,9 +330,9 @@ Note that a `:presence` and `:uniqueness` validation is automatically defined on
|
|
315
330
|
|
316
331
|
### has\_enumerated
|
317
332
|
|
318
|
-
First of all, note that you *could* specify the relationship to an `acts_as_enumerated` class using the belongs_to
|
319
|
-
However, `has_enumerated` is preferable because you aren't really associated to the enumerated value, you
|
320
|
-
the `has_enumerated` macro behaves more like an aggregation than an association.
|
333
|
+
First of all, note that you *could* specify the relationship to an `acts_as_enumerated` class using the `belongs_to`
|
334
|
+
association. However, `has_enumerated` is preferable because you aren't really associated to the enumerated value, you
|
335
|
+
are *aggregating* it. As such, the `has_enumerated` macro behaves more like an aggregation than an association.
|
321
336
|
|
322
337
|
class Booking < ActiveRecord::Base
|
323
338
|
has_enumerated :status, :class_name => 'BookingStatus',
|
@@ -328,24 +343,26 @@ the `has_enumerated` macro behaves more like an aggregation than an association.
|
|
328
343
|
:create_scope => false #Setting this to false disables the automatic creation of the 'with_status' scope.
|
329
344
|
end
|
330
345
|
|
331
|
-
By default, the foreign key is interpreted to be the name of your has\_enumerated field (in this case '
|
332
|
-
chose to make the column name 'status\_id' for the sake of brevity, we must explicitly designate
|
333
|
-
`:class_name` is the camelized version of the name for your has\_enumerated
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
346
|
+
By default, the foreign key is interpreted to be the name of your has\_enumerated field (in this case 'booking\_status')
|
347
|
+
plus '\_id'. Since we chose to make the column name 'status\_id' for the sake of brevity, we must explicitly designate
|
348
|
+
it. Additionally, the default value for `:class_name` is the camelized version of the name for your has\_enumerated
|
349
|
+
field. `:on_lookup_failure` is explained below. `:permit_empty_name` is an optional flag to disable automatic
|
350
|
+
conversion of empty strings to nil. It is typically desirable to have `booking.update_attributes(:status => '')`
|
351
|
+
assign status\_id to a nil rather than raise an Error, as you'll be often calling `update_attributes` with form data, but
|
352
|
+
the choice is yours. Setting a `:default` option will generate an after\_initialize callback to set a default value on
|
353
|
+
the attribute unless a non-nil value has already been set.
|
338
354
|
|
339
355
|
With that, your Booking class will have the following methods defined:
|
340
356
|
|
341
357
|
#### status
|
342
358
|
|
343
|
-
Returns the BookingStatus with an id that matches the value in the Booking.
|
359
|
+
Returns the BookingStatus with an id that matches the value in the Booking.status\_id.
|
344
360
|
|
345
361
|
#### status=(arg)
|
346
362
|
|
347
|
-
Sets the value for Booking.
|
348
|
-
short-hand, you can also pass it the 'name' of a BookingStatus instance, either as a 'string' or :symbol, or pass in the
|
363
|
+
Sets the value for Booking.status\_id using the id of the BookingStatus instance passed as an argument. As a
|
364
|
+
short-hand, you can also pass it the 'name' of a BookingStatus instance, either as a 'string' or :symbol, or pass in the
|
365
|
+
id directly.
|
349
366
|
|
350
367
|
example:
|
351
368
|
|
@@ -359,34 +376,38 @@ or:
|
|
359
376
|
|
360
377
|
mybooking.status = BookingStatus[:confirmed]
|
361
378
|
|
362
|
-
The `:on_lookup_failure` option in
|
363
|
-
where the argument passed to `status=(arg)` is invalid. By default, an invalid value will cause an
|
379
|
+
The `:on_lookup_failure` option in has\_enumerated is there because you may want to create an error handler for
|
380
|
+
situations where the argument passed to `status=(arg)` is invalid. By default, an invalid value will cause an
|
381
|
+
ArgumentError to be raised.
|
364
382
|
|
365
|
-
Of course, this may not be optimal in your situation. In this case you can specify an *instance* method to be called in
|
383
|
+
Of course, this may not be optimal in your situation. In this case you can specify an *instance* method to be called in
|
384
|
+
the case of a lookup failure. The method signature is as follows:
|
366
385
|
|
367
386
|
your_lookup_handler(operation, name, name_foreign_key, acts_enumerated_class_name, lookup_value)
|
368
387
|
|
369
|
-
The 'operation' arg will be either `:read` or `:write`. In the case of `:read` you are expected to return something or
|
370
|
-
while in the case of a `:write` you don't have to return anything.
|
388
|
+
The 'operation' arg will be either `:read` or `:write`. In the case of `:read` you are expected to return something or
|
389
|
+
raise an exception, while in the case of a `:write` you don't have to return anything.
|
371
390
|
|
372
|
-
Note that there's enough information in the method signature that you can specify one method to handle all lookup
|
373
|
-
for all has\_enumerated fields if you happen to have more than one defined in your model.
|
391
|
+
Note that there's enough information in the method signature that you can specify one method to handle all lookup
|
392
|
+
failures for all has\_enumerated fields if you happen to have more than one defined in your model.
|
374
393
|
|
375
|
-
NOTE: A `nil` is always considered to be a valid value for `status=(arg)` since it's assumed you're trying to null out
|
376
|
-
The `:on_lookup_failure` will be bypassed.
|
394
|
+
NOTE: A `nil` is always considered to be a valid value for `status=(arg)` since it's assumed you're trying to null out
|
395
|
+
the foreign key. The `:on_lookup_failure` will be bypassed.
|
377
396
|
|
378
397
|
#### with\_enumerated\_attribute scope
|
379
398
|
|
380
|
-
Unless the `:
|
381
|
-
allows us to say things like:
|
399
|
+
Unless the `:create_scope` option is set to `false`, a scope is automatically created that takes a list of enums as
|
400
|
+
arguments. This allows us to say things like:
|
382
401
|
|
383
402
|
Booking.with_status :confirmed, :received
|
384
403
|
|
385
|
-
Strings, symbols, ids, or enum instances are all valid arguments. For example, the following would be valid, though not
|
386
|
-
for obvious reasons.
|
404
|
+
Strings, symbols, ids, or enum instances are all valid arguments. For example, the following would be valid, though not
|
405
|
+
recommended for obvious reasons.
|
387
406
|
|
388
407
|
Booking.with_status 1, 'confirmed', BookingStatus[:rejected]
|
389
408
|
|
409
|
+
As of version 0.5.5, it also aliases a pluralized version of the scope, i.e. `:with_statuses`
|
410
|
+
|
390
411
|
### ActiveRecord::Base Extensions
|
391
412
|
|
392
413
|
The following methods are added to ActiveRecord::Base as class methods.
|
@@ -404,9 +425,11 @@ Returns an array of attributes which are enumerated.
|
|
404
425
|
|
405
426
|
In many instances, your `acts_as_enumerated` classes will do nothing more than just act as enumerated.
|
406
427
|
|
407
|
-
In that case there isn't much point cluttering up your models directory with those class files. You can use
|
428
|
+
In that case there isn't much point cluttering up your models directory with those class files. You can use
|
429
|
+
ActiveRecord::VirtualEnumerations to reduce that clutter.
|
408
430
|
|
409
|
-
Copy virtual\_enumerations\_sample.rb to Rails.root/config/initializers/virtual\_enumerations.rb and configure it
|
431
|
+
Copy virtual\_enumerations\_sample.rb to Rails.root/config/initializers/virtual\_enumerations.rb and configure it
|
432
|
+
accordingly.
|
410
433
|
|
411
434
|
See virtual\_enumerations\_sample.rb in the examples directory of this gem for a full description.
|
412
435
|
|
@@ -1,15 +1,56 @@
|
|
1
1
|
# Copyright (c) 2005 Trevor Squires
|
2
|
+
# Copyright (c) 2012 Arthur Shagall
|
2
3
|
# Released under the MIT License. See the LICENSE file for more details.
|
3
4
|
|
4
5
|
module ActiveRecord
|
5
6
|
module Acts
|
6
7
|
module Enumerated
|
7
|
-
|
8
|
-
super
|
9
|
-
base.extend(MacroMethods)
|
10
|
-
end
|
8
|
+
extend ActiveSupport::Concern
|
11
9
|
|
12
|
-
module
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
# Declares the model as enumerated. See the README for detailed usage instructions.
|
13
|
+
#
|
14
|
+
# === Supported options
|
15
|
+
# [:conditions]
|
16
|
+
# SQL search conditions
|
17
|
+
# [:order]
|
18
|
+
# SQL load order clause
|
19
|
+
# [:on_lookup_failure]
|
20
|
+
# Specifies the name of a class method to invoke when the +[]+ method is unable to locate a BookingStatus
|
21
|
+
# record for arg. The default is the built-in :enforce_none which returns nil. There are also built-ins for
|
22
|
+
# :enforce_strict (raise and exception regardless of the type for arg), :enforce_strict_literals (raises an
|
23
|
+
# exception if the arg is a Fixnum or Symbol), :enforce_strict_ids (raises and exception if the arg is a
|
24
|
+
# Fixnum) and :enforce_strict_symbols (raises an exception if the arg is a Symbol). The purpose of the
|
25
|
+
# :on_lookup_failure option is that a) under some circumstances a lookup failure is a Bad Thing and action
|
26
|
+
# should be taken, therefore b) a fallback action should be easily configurable.
|
27
|
+
# [:name_column]
|
28
|
+
# Override for the 'name' column. By default, assumed to be 'name'.
|
29
|
+
#
|
30
|
+
# === Examples
|
31
|
+
#
|
32
|
+
# ====Example 1
|
33
|
+
# class BookingStatus < ActiveRecord::Base
|
34
|
+
# acts_as_enumerated
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# ====Example 2
|
38
|
+
# class BookingStatus < ActiveRecord::Base
|
39
|
+
# acts_as_enumerated :on_lookup_failure => :enforce_strict
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# ====Example 3
|
43
|
+
# class BookingStatus < ActiveRecord::Base
|
44
|
+
# acts_as_enumerated :conditions => [:exclude => false],
|
45
|
+
# :order => 'created_at DESC',
|
46
|
+
# :on_lookup_failure => :lookup_failed,
|
47
|
+
# :name_column => :status_code
|
48
|
+
#
|
49
|
+
# def self.lookup_failed(arg)
|
50
|
+
# logger.error("Invalid status code lookup #{arg.inspect}")
|
51
|
+
# nil
|
52
|
+
# end
|
53
|
+
# end
|
13
54
|
def acts_as_enumerated(options = {})
|
14
55
|
valid_keys = [:conditions, :order, :on_lookup_failure, :name_column]
|
15
56
|
options.assert_valid_keys(*valid_keys)
|
@@ -25,11 +66,11 @@ module ActiveRecord
|
|
25
66
|
end
|
26
67
|
write_inheritable_attribute(:acts_enumerated_name_column, name_column)
|
27
68
|
|
28
|
-
unless self.is_a? ActiveRecord::Acts::Enumerated::
|
29
|
-
extend ActiveRecord::Acts::Enumerated::
|
69
|
+
unless self.is_a? ActiveRecord::Acts::Enumerated::EnumClassMethods
|
70
|
+
extend ActiveRecord::Acts::Enumerated::EnumClassMethods
|
30
71
|
|
31
72
|
class_eval do
|
32
|
-
include ActiveRecord::Acts::Enumerated::
|
73
|
+
include ActiveRecord::Acts::Enumerated::EnumInstanceMethods
|
33
74
|
|
34
75
|
before_save :enumeration_model_update
|
35
76
|
before_destroy :enumeration_model_update
|
@@ -43,7 +84,7 @@ module ActiveRecord
|
|
43
84
|
end
|
44
85
|
end
|
45
86
|
|
46
|
-
module
|
87
|
+
module EnumClassMethods
|
47
88
|
attr_accessor :enumeration_model_updates_permitted
|
48
89
|
|
49
90
|
# Returns all the enum values. Caches results after the first time this method is run.
|
@@ -194,7 +235,7 @@ module ActiveRecord
|
|
194
235
|
|
195
236
|
end
|
196
237
|
|
197
|
-
module
|
238
|
+
module EnumInstanceMethods
|
198
239
|
# Behavior depends on the type of +arg+.
|
199
240
|
#
|
200
241
|
# * If +arg+ is +nil+, returns +false+.
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# Copyright (c) 2005 Trevor Squires
|
2
|
+
# Copyright (c) 2012 Arthur Shagall
|
2
3
|
# Released under the MIT License. See the LICENSE file for more details.
|
3
4
|
|
4
5
|
module ActiveRecord
|
5
6
|
module Aggregations # :nodoc:
|
6
7
|
module HasEnumerated # :nodoc:
|
7
8
|
|
8
|
-
|
9
|
-
super
|
10
|
-
base.extend(MacroMethods)
|
11
|
-
end
|
9
|
+
extend ActiveSupport::Concern
|
12
10
|
|
13
|
-
module
|
11
|
+
module ClassMethods
|
14
12
|
|
13
|
+
# Returns a list of all the attributes on the ActiveRecord model which are enumerated.
|
15
14
|
def enumerated_attributes
|
16
15
|
@enumerated_attributes ||= []
|
17
16
|
end
|
18
17
|
|
18
|
+
# Returns +true+ if +attribute+ is an enumerated attribute, +false+ otherwise.
|
19
19
|
def has_enumerated?(attribute)
|
20
|
-
return false
|
20
|
+
return false if attribute.nil?
|
21
21
|
enumerated_attributes.include? attribute.to_s
|
22
22
|
end
|
23
23
|
|
@@ -26,7 +26,7 @@ module ActiveRecord
|
|
26
26
|
#
|
27
27
|
# === Supported options
|
28
28
|
# [:class_name]
|
29
|
-
# Name of the enum class. By default it is the
|
29
|
+
# Name of the enum class. By default it is the camelized version of the has_enumerated attribute.
|
30
30
|
# [:foreign_key]
|
31
31
|
# Explicitly set the foreign key column. By default it's assumed to be your_enumerated_attribute_name_id.
|
32
32
|
# [:on_lookup_failure]
|
@@ -132,10 +132,20 @@ module ActiveRecord
|
|
132
132
|
unless create_scope == false
|
133
133
|
module_eval( <<-end_eval, __FILE__, __LINE__)
|
134
134
|
scope :with_#{name}, lambda { |*args|
|
135
|
-
ids = args.map{|arg|
|
135
|
+
ids = args.map{ |arg|
|
136
|
+
n = #{class_name}[arg]
|
137
|
+
}
|
136
138
|
where(:#{foreign_key} => ids)
|
137
139
|
}
|
138
140
|
end_eval
|
141
|
+
|
142
|
+
if (name_p = name.pluralize) != name
|
143
|
+
module_eval( <<-end_eval, __FILE__, __LINE__)
|
144
|
+
class << self
|
145
|
+
alias_method :with_#{name_p}, :with_#{name}
|
146
|
+
end
|
147
|
+
end_eval
|
148
|
+
end
|
139
149
|
end
|
140
150
|
|
141
151
|
end #has_enumerated
|
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
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 4
|
10
|
-
version: 0.5.4
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
requirement: &
|
15
|
+
date: 2012-02-06 00:00:00.000000000Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rails
|
19
|
+
requirement: &15454380 !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
|
-
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
|
27
|
+
version_requirements: *15454380
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: jeweler
|
30
|
+
requirement: &15442580 !ruby/object:Gem::Requirement
|
55
31
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
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
|
-
|
68
|
-
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *15442580
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rspec
|
41
|
+
requirement: &15440860 !ruby/object:Gem::Requirement
|
69
42
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
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: *15440860
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: sqlite3
|
52
|
+
requirement: &15439280 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
80
58
|
type: :development
|
81
|
-
|
82
|
-
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *15439280
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: genspec
|
63
|
+
requirement: &15438200 !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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: *15438200
|
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
|
80
|
+
|
81
|
+
when it''s used for analytics or reporting.
|
102
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,30 @@ 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
|
-
|
141
|
-
segments:
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
segments:
|
142
119
|
- 0
|
143
|
-
|
144
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
hash: -1905981418849188503
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
122
|
none: false
|
146
|
-
requirements:
|
147
|
-
- -
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
|
150
|
-
segments:
|
151
|
-
- 0
|
152
|
-
version: "0"
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
153
127
|
requirements: []
|
154
|
-
|
155
128
|
rubyforge_project:
|
156
129
|
rubygems_version: 1.8.10
|
157
130
|
signing_key:
|
158
131
|
specification_version: 3
|
159
|
-
summary: Allows you to treat instances of your ActiveRecord models as though they
|
132
|
+
summary: Allows you to treat instances of your ActiveRecord models as though they
|
133
|
+
were an enumeration of values
|
160
134
|
test_files: []
|
161
|
-
|