Module: AASM::ClassMethods
- Defined in:
- lib/aasm/aasm.rb
Instance Method Summary collapse
-
#aasm(*args, &block) ⇒ Object
this is the entry point for all state and event definitions.
-
#inherited(base) ⇒ Object
make sure inheritance (aka subclassing) works with AASM.
Instance Method Details
#aasm(*args, &block) ⇒ Object
this is the entry point for all state and event definitions
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/aasm/aasm.rb', line 26 def aasm(*args, &block) if args[0].is_a?(Symbol) || args[0].is_a?(String) # using custom name state_machine_name = args[0].to_sym = args[1] || {} else # using the default state_machine_name state_machine_name = :default = args[0] || {} end AASM::StateMachineStore.fetch(self, true).register(state_machine_name, AASM::StateMachine.new(state_machine_name)) # use a default despite the DSL configuration default. # this is because configuration hasn't been setup for the AASM class but we are accessing a DSL option already for the class. aasm_klass = [:with_klass] || AASM::Base raise ArgumentError, "The class #{aasm_klass} must inherit from AASM::Base!" unless aasm_klass.ancestors.include?(AASM::Base) @aasm ||= {} if @aasm[state_machine_name] # make sure to use provided options .each do |key, value| @aasm[state_machine_name].state_machine.config.send("#{key}=", value) end else # create a new base @aasm[state_machine_name] = aasm_klass.new( self, state_machine_name, AASM::StateMachineStore.fetch(self, true).machine(state_machine_name), ) end @aasm[state_machine_name].instance_eval(&block) if block # new DSL @aasm[state_machine_name] end |
#inherited(base) ⇒ Object
make sure inheritance (aka subclassing) works with AASM
19 20 21 22 23 |
# File 'lib/aasm/aasm.rb', line 19 def inherited(base) AASM::StateMachineStore.register(base, self) super end |