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 * Specs and bug fixes for the ActiveRecordPersistence, keeping persistence columns in sync
Allowing for nil values in states for active record 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] 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. * Added aasm_states_for_select that will return a select friendly collection of states.

View File

@ -22,9 +22,9 @@ end
$package_version = CURRENT_VERSION $package_version = CURRENT_VERSION
PKG_FILES = FileList['[A-Z]*', PKG_FILES = FileList['[A-Z]*',
'lib/**/*.rb', 'lib/**/*.rb',
'doc/**/*' 'doc/**/*'
] ]
desc 'Generate documentation for the acts as state machine plugin.' desc 'Generate documentation for the acts as state machine plugin.'
rd = Rake::RDocTask.new(:rdoc) do |rdoc| rd = Rake::RDocTask.new(:rdoc) do |rdoc|
@ -45,8 +45,8 @@ else
s.version = $package_version s.version = $package_version
s.summary = 'State machine mixin for Ruby objects' s.summary = 'State machine mixin for Ruby objects'
s.description = <<-EOF s.description = <<-EOF
AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects. AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.
EOF EOF
s.files = PKG_FILES.to_a s.files = PKG_FILES.to_a
s.require_path = 'lib' s.require_path = 'lib'
s.has_rdoc = true s.has_rdoc = true
@ -73,7 +73,7 @@ else
t.rcov = true t.rcov = true
t.rcov_opts = ['--exclude', 'spec'] t.rcov_opts = ['--exclude', 'spec']
end end
desc "Run all examples" desc "Run all examples"
Spec::Rake::SpecTask.new('spec') do |t| Spec::Rake::SpecTask.new('spec') do |t|
t.spec_files = FileList['spec/**/*.rb'] t.spec_files = FileList['spec/**/*.rb']
@ -82,4 +82,13 @@ else
end end
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] task :default => [:spec]

View File

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