mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Merge in Jan De Poorter's [DefV] named_scope addition to AR persistence layer, with some organizational clean up.
This commit is contained in:
parent
270d9e1244
commit
83bbe4d082
2 changed files with 24 additions and 1 deletions
|
@ -1,5 +1,9 @@
|
|||
* Use named_scope in AR persistence layer, if available [Jan De Poorter]
|
||||
|
||||
* Incremented version number
|
||||
|
||||
* Cleaned up aasm_states_for_select to return the value as a string
|
||||
|
||||
* 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
|
||||
|
|
|
@ -36,7 +36,19 @@ module AASM
|
|||
base.send(:include, AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
|
||||
base.send(:include, AASM::Persistence::ActiveRecordPersistence::ReadState) unless base.method_defined?(:aasm_read_state)
|
||||
base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteState) unless base.method_defined?(:aasm_write_state)
|
||||
base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)
|
||||
base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)
|
||||
|
||||
if base.respond_to?(:named_scope)
|
||||
base.extend(AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods)
|
||||
|
||||
base.class_eval do
|
||||
class << self
|
||||
alias_method :aasm_state_without_named_scope, :aasm_state
|
||||
alias_method :aasm_state, :aasm_state_with_named_scope
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
base.before_validation_on_create :aasm_ensure_initial_state
|
||||
end
|
||||
|
||||
|
@ -211,6 +223,13 @@ module AASM
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
module NamedScopeMethods
|
||||
def aasm_state_with_named_scope name, options = {}
|
||||
aasm_state_without_named_scope name, options
|
||||
self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.scopes.include?(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue