Sha256: 2e96f342721736f8d8409b8456de60c06691c2f0dbc8c40d1c56df6d33ce7849

Contents?: true

Size: 709 Bytes

Versions: 1

Compression:

Stored size: 709 Bytes

Contents

module Mutator
  class Transition
    attr_reader :to, :from, :machine

    def initialize opts
      @to = opts.fetch(:to)
      @from = opts.fetch(:from)
      @machine = opts.fetch(:machine)
    end

    def call
      stateholder.state = to if valid?
    end

    def valid?
      transitions.length > 0
    end

    def stateholder
      machine.stateholder
    end

    def == other
      to == other.to && from == other.from && machine == other.machine
    end

    def eql? other
      public_send :==, other
    end

  protected

    def transitions
      machine.transitions.select do |transition|
        transition[:to] == to && Array(transition[:from]).include?(from)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mutator-0.2.0 lib/mutator/transition.rb