power_enum 0.8.0 → 0.8.1
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 +13 -0
- data/lib/active_record/acts/enumerated.rb +17 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -265,6 +265,19 @@ method.
|
|
265
265
|
|
266
266
|
`BookingStatus.names` will return all the names of the defined enums as an array of symbols.
|
267
267
|
|
268
|
+
##### update\_enumerations\_model (since version 0.8.1)
|
269
|
+
|
270
|
+
The preferred mechanism to update an enumerations model in migrations and similar. Pass in a block to this method to
|
271
|
+
to perform any updates.
|
272
|
+
|
273
|
+
Example:
|
274
|
+
|
275
|
+
BookingStatus.update_enumerations_model do
|
276
|
+
BookingStatus.create :name => 'Foo',
|
277
|
+
:description => 'Bar',
|
278
|
+
:active => false
|
279
|
+
end
|
280
|
+
|
268
281
|
#### Instance Methods
|
269
282
|
|
270
283
|
Each enumeration model gets the following instance methods.
|
@@ -189,6 +189,23 @@ module ActiveRecord
|
|
189
189
|
@all = @all_by_name = @all_by_id = @all_active = nil
|
190
190
|
end
|
191
191
|
|
192
|
+
# The preferred method to update an enumerations model. The same
|
193
|
+
# warnings as 'purge_enumerations_cache' and
|
194
|
+
# 'enumerations_model_update_permitted' apply. Pass a block to this
|
195
|
+
# method (no args) where you perform your updates. Cache will be
|
196
|
+
# flushed automatically.
|
197
|
+
def update_enumerations_model
|
198
|
+
if block_given?
|
199
|
+
begin
|
200
|
+
self.enumeration_model_updates_permitted = true
|
201
|
+
yield
|
202
|
+
ensure
|
203
|
+
purge_enumerations_cache
|
204
|
+
self.enumeration_model_updates_permitted = false
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
192
209
|
# Returns the name of the column this enum uses as the basic underlying value.
|
193
210
|
def name_column
|
194
211
|
@name_column ||= self.acts_enumerated_name_column
|
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.8.
|
4
|
+
version: 0.8.1
|
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-07-
|
15
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rails
|
@@ -159,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
segments:
|
161
161
|
- 0
|
162
|
-
hash:
|
162
|
+
hash: -3595849255400761533
|
163
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
164
|
none: false
|
165
165
|
requirements:
|