Sha256: 9ca3618aa12f8790dea72c311eab8266bf2b636ae85a48fe411a317d21495236

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

module AASM
  class StateMachine

    # the following two methods provide the storage of all state machines
    def self.[](klass)
      (@machines ||= {})[klass.to_s]
    end

    def self.[]=(klass, machine)
      (@machines ||= {})[klass.to_s] = machine
    end

    attr_accessor :states, :events, :initial_state, :config

    def initialize
      @initial_state = nil
      @states = []
      @events = {}
      @config = AASM::Configuration.new
    end

    # called internally by Ruby 1.9 after clone()
    def initialize_copy(orig)
      super
      @states = @states.dup
      @events = @events.dup
    end

    def add_state(name, klass, options)
      set_initial_state(name, options)

      # allow reloading, extending or redefining a state
      @states.delete(name) if @states.include?(name)

      @states << AASM::Core::State.new(name, klass, options)
    end

    private

    def set_initial_state(name, options)
      @initial_state = name if options[:initial] || !initial_state
    end

  end # StateMachine
end # AASM

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aasm-4.2.0 lib/aasm/state_machine.rb
aasm-4.1.1 lib/aasm/state_machine.rb
aasm-4.1.0 lib/aasm/state_machine.rb
aasm-4.0.8 lib/aasm/state_machine.rb
aasm-4.0.7 lib/aasm/state_machine.rb
aasm-4.0.6 lib/aasm/state_machine.rb
aasm-4.0.5 lib/aasm/state_machine.rb
aasm-4.0.4 lib/aasm/state_machine.rb