power_enum 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -57,8 +57,8 @@ then run
57
57
  This package adds:
58
58
  - Two mixins and a helper to ActiveRecord
59
59
  - Methods to migrations to simplify the creation of backing tables
60
- - A generator to make generating enums easy
61
- - Custom RSpec matchers to streamline the testing of enums and enumerated attributes (Since version 0.6.0)
60
+ - Two generators to streamline working with enums
61
+ - Custom RSpec matchers to streamline the testing of enums and enumerated attributes
62
62
 
63
63
  `acts_as_enumerated` provides capabilities to treat your model and its records as an enumeration.
64
64
  At a minimum, the database table for an acts\_as\_enumerated must contain an 'id' column and a column
@@ -94,7 +94,7 @@ You should see output similar to this:
94
94
  create test/unit/booking_status_test.rb
95
95
 
96
96
  That's all you need to get started. In many cases, no further work on the enum is necessary. You can run `rails generate enum --help`
97
- to see a description of the generator options. Notice, that while a unit tests is generated by default, a fixture isn't. That is because
97
+ to see a description of the generator options. Notice, that while a unit test is generated by default, a fixture isn't. That is because
98
98
  fixtures are not an ideal way to test acts\_as\_enumerated models. I generally prefer having a hook to seed the database from seeds.rb
99
99
  from a pre-test Rake task.
100
100
 
@@ -327,6 +327,16 @@ BookingStatus.update_enumerations_model do
327
327
  end
328
328
  ```
329
329
 
330
+ Example 2 (since version 0.9.3):
331
+
332
+ ```ruby
333
+ BookingStatus.update_enumerations_model do |klass|
334
+ klass.create :name => 'Foo',
335
+ :description => 'Bar',
336
+ :active => false
337
+ end
338
+ ```
339
+
330
340
  ##### acts\_as\_enumerated? (since version 0.8.6)
331
341
 
332
342
  Returns `true` for ActiveRecord models that act as enumerated, `false` for others. So
@@ -565,7 +575,7 @@ you can use ActiveRecord::VirtualEnumerations to reduce that clutter.
565
575
 
566
576
  Create a custom Rails initializer: Rails.root/config/initializers/virtual\_enumerations.rb
567
577
 
568
- As of version 0.9.2, there is a built in generator for this:
578
+ NOTE: As of version 0.9.2, there is a built in generator for this:
569
579
 
570
580
  ```bash
571
581
  rails generate virtual_enumerations_initializer
@@ -235,13 +235,19 @@ module PowerEnum::Enumerated
235
235
  # The preferred method to update an enumerations model. The same
236
236
  # warnings as 'purge_enumerations_cache' and
237
237
  # 'enumerations_model_update_permitted' apply. Pass a block to this
238
- # method (no args) where you perform your updates. Cache will be
239
- # flushed automatically.
240
- def update_enumerations_model
238
+ # method where you perform your updates. Cache will be
239
+ # flushed automatically. If your block takes an argument, will pass in
240
+ # the model class. The argument is optional.
241
+ def update_enumerations_model(&block)
241
242
  if block_given?
242
243
  begin
243
244
  self.enumeration_model_updates_permitted = true
244
- yield
245
+ case block.arity
246
+ when 0
247
+ yield
248
+ else
249
+ yield self
250
+ end
245
251
  ensure
246
252
  purge_enumerations_cache
247
253
  self.enumeration_model_updates_permitted = false
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.2
4
+ version: 0.9.3
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-09-22 00:00:00.000000000 Z
15
+ date: 2012-09-24 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: -4218676546768787093
148
+ hash: -2052291500201023565
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements: