lib/aasm/aasm.rb in aasm-2.3.1 vs lib/aasm/aasm.rb in aasm-2.4.0
- old
+ new
@@ -19,65 +19,53 @@
def inherited(klass)
AASM::StateMachine[klass] = AASM::StateMachine[self].clone
super
end
+ def aasm(options={}, &block)
+ @aasm ||= AASM::Base.new(self, options)
+ @aasm.instance_eval(&block) if block
+ @aasm
+ end
+
def aasm_initial_state(set_state=nil)
if set_state
+ # deprecated
AASM::StateMachine[self].initial_state = set_state
else
AASM::StateMachine[self].initial_state
end
end
+ # deprecated
def aasm_initial_state=(state)
AASM::StateMachine[self].initial_state = state
end
+ # deprecated
def aasm_state(name, options={})
- sm = AASM::StateMachine[self]
- sm.create_state(name, options)
- sm.initial_state = name unless sm.initial_state
-
- define_method("#{name.to_s}?") do
- aasm_current_state == name
- end
+ aasm.state(name, options)
end
+ # deprecated
def aasm_event(name, options = {}, &block)
- sm = AASM::StateMachine[self]
-
- unless sm.events.has_key?(name)
- sm.events[name] = AASM::SupportingClasses::Event.new(name, options, &block)
- end
-
- # an addition over standard aasm so that, before firing an event, you can ask
- # may_event? and get back a boolean that tells you whether the guard method
- # on the transition will let this happen.
- define_method("may_#{name.to_s}?") do |*args|
- aasm_test_event(name, *args)
- end
-
- define_method("#{name.to_s}!") do |*args|
- aasm_fire_event(name, true, *args)
- end
-
- define_method("#{name.to_s}") do |*args|
- aasm_fire_event(name, false, *args)
- end
+ aasm.event(name, options, &block)
end
+ # deprecated
def aasm_states
- AASM::StateMachine[self].states
+ aasm.states
end
+ # deprecated
def aasm_events
- AASM::StateMachine[self].events
+ aasm.events
end
+ # deprecated
def aasm_states_for_select
- AASM::StateMachine[self].states.map { |state| state.for_select }
+ aasm.states_for_select
end
def human_event_name(event)
AASM::Localizer.new.human_event_name(self, event)
end
@@ -124,10 +112,10 @@
def human_state
AASM::Localizer.new.human_state(self)
end
- private
+private
def set_aasm_current_state_with_persistence(state)
save_success = true
if self.respond_to?(:aasm_write_state) || self.private_methods.include?('aasm_write_state')
save_success = aasm_write_state(state)