lib/mutator/transition.rb in mutator-0.1.0 vs lib/mutator/transition.rb in mutator-0.2.0
- old
+ new
@@ -1,12 +1,13 @@
module Mutator
class Transition
attr_reader :to, :from, :machine
- def initialize(opts)
- require_parameters!(opts)
- @to, @from, @machine = opts[:to], opts[:from], opts[: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
@@ -17,28 +18,22 @@
def stateholder
machine.stateholder
end
- def ==(other)
+ def == other
to == other.to && from == other.from && machine == other.machine
end
- def eql?(other)
- public_send(:==, other)
+ def eql? other
+ public_send :==, other
end
protected
def transitions
machine.transitions.select do |transition|
- transition[:to] == to && transition[:from].include?(from)
- end
- end
-
- def require_parameters!(opts)
- [:to, :from, :machine].each do |attr|
- fail ArgumentError, "must provide #{attr}" unless opts[attr]
+ transition[:to] == to && Array(transition[:from]).include?(from)
end
end
end
end