1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

updated docs

This commit is contained in:
Jeff Dean 2008-04-29 02:08:51 -04:00
parent a0bb1c404c
commit 277373b41a
3 changed files with 33 additions and 11 deletions

View file

@ -1,5 +1,7 @@
* Specs and bug fixes for the ActiveRecordPersistence, keeping persistence columns in sync
Allowing for nil values in states for active record
Only set state to default state before_validation_on_create
New rake task to uninstall, build and reinstall the gem (useful for development)
New non-(!) methods that allow for firing events without persisting [Jeff Dean]
* Added aasm_states_for_select that will return a select friendly collection of states.

View file

@ -82,4 +82,13 @@ else
end
end
if !defined?(Gem)
puts "Package target requires RubyGEMs"
else
desc "sudo gem uninstall aasm && rake gem && sudo gem install pkg/aasm-3.0.0.gem"
task :reinstall do
puts `sudo gem uninstall aasm && rake gem && sudo gem install pkg/aasm-3.0.0.gem`
end
end
task :default => [:spec]

View file

@ -11,6 +11,10 @@ module AASM
# * WriteState
# * WriteStateWithoutPersistence
#
# Adds
#
# before_validation_on_create :aasm_ensure_initial_state
#
# As a result, it doesn't matter when you define your methods - the following 2 are equivalent
#
# class Foo < ActiveRecord::Base
@ -94,13 +98,20 @@ module AASM
private
# Called from before_validation_on_create to ensure
# that if there is a nil value in the underlying aasm_state
# column, the initial state is used instead
# Ensures that if the aasm_state column is nil and the record is new
# that the initial state gets populated before validation on create
#
# foo = Foo.new
# foo.save
# foo.aasm_state # => the initial state
# foo.aasm_state # => nil
# foo.valid?
# foo.aasm_state # => "open" (where :open is the initial state)
#
#
# foo = Foo.find(:first)
# foo.aasm_state # => 1
# foo.aasm_state = nil
# foo.valid?
# foo.aasm_state # => nil
#
def aasm_ensure_initial_state
send("#{self.class.aasm_column}=", self.aasm_current_state.to_s)