Module: Golem
- Defined in:
- lib/golem/model/transition.rb,
lib/golem.rb,
lib/golem/model/event.rb,
lib/golem/model/state.rb,
lib/golem/dsl/event_def.rb,
lib/golem/dsl/state_def.rb,
lib/golem/model/callback.rb,
lib/golem/model/condition.rb,
lib/golem/dsl/decision_def.rb,
lib/golem/dsl/transition_def.rb,
lib/golem/model/state_machine.rb,
lib/golem/dsl/state_machine_def.rb,
lib/golem/util/element_collection.rb
Overview
To change this template, choose Tools | Templates and open the template in the editor.
Defined Under Namespace
Modules: ClassMethods, DSL, Model, Util Classes: DefinitionSyntaxError, ImpossibleEvent, InvalidStateError
Class Method Summary collapse
Class Method Details
.included(mod) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/golem.rb', line 7 def self.included(mod) mod.extend Golem::ClassMethods # Override the initialize method in the object we're imbuing with statemachine # functionality so that we can do statemachine initialization when the object # is instantiated. # # For ActiveRecord, we use the after_initialize callback instead. # FIXME: should use an ActiveRecord::Observer here since this will conflict with # any user-set after_initialize callback. mod.class_eval do if Object.const_defined?('ActiveRecord') && mod < ActiveRecord::Base after_initialize do if respond_to?(:statemachines) self.statemachines.each{|name, sm| sm.init(self)} end end else alias_method :_initialize, :initialize def initialize(*args) # call the original initialize _initialize(*args) if respond_to?(:statemachines) self.statemachines.each{|name, sm| sm.init(self)} end end end end end |