Sha256: eb45d9bff3cd4daff406d82b8adbf66e2ddc0b654526486ac0c7e855565e9859

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

require "./lib/class_attribute"

module TinyState
  def self.included(base)
    base.extend ClassMethods
    base.class_eval do
      include ClassAttribute
      tiny_class_attribute :tiny_state_machines, default: {}
    end
  end

  module ClassMethods
    def tiny_state(attribute = :state, &)
      state_machine = TinyState::StateMachine.new(attribute:)

      state_machine.instance_eval(&)
      state_machine.send(:register_events, self)

      tiny_state_machines[attribute] = state_machine
    end
  end

  def tiny_state_machine(attribute = nil)
    if attribute
      self.class.tiny_state_machines[attribute]
    else
      self.class.tiny_state_machines.values.first
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tiny_state-0.2.0 lib/tiny_state/tiny_state.rb