Sha256: 9a5d2c68ccd9fb9a897d51a859054d301d226b61af50d7ddf3020911d247db68

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

module StateMachina
  class State
    attr_reader :model_name, :machine_name, :name, :metadata
    attr_accessor :machine

    def initialize(model_name, machine_name, name, metadata: {})
      @model_name = model_name
      @machine_name = machine_name
      @name = name.to_s
      @metadata = metadata
    end

    def before?(other_state_name)
      return false if machine.nil?

      !machine.states.before(machine.current_state_name).map(&:name).include?(other_state_name)
    end

    def before_inclusive?(other_state_name)
      return false if machine.nil?

      !machine.states.before_inclusive(machine.current_state_name).map(&:name).include?(other_state_name)
    end

    def past?(other_state_name)
      return false if machine.nil?

      !machine.states.past(machine.current_state_name).map(&:name).include?(other_state_name)
    end

    def past_inclusive?(other_state_name)
      return false if machine.nil?

      !machine.states.past_inclusive(machine.current_state_name).map(&:name).include?(other_state_name)
    end

    def between?(from_state_name, to_state_name)
      return false if machine.nil?

      machine.states.between(from_state_name, to_state_name).map(&:name).include?(machine.current_state_name)
    end

    def between_inclusive?(from_state_name, to_state_name)
      return false if machine.nil?

      machine.states.between_inclusive(from_state_name, to_state_name).map(&:name).include?(machine.current_state_name)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
state_machina-0.1.6 lib/state_machina/state.rb
state_machina-0.1.5 lib/state_machina/state.rb
state_machina-0.1.4 lib/state_machina/state.rb
state_machina-0.1.3 lib/state_machina/state.rb
state_machina-0.1.2 lib/state_machina/state.rb
state_machina-0.1.1 lib/state_machina/state.rb
state_machina-0.1.0 lib/state_machina/state.rb