class Finite::Event
The event class. Represents an event in the state machine
Attributes
callbacks[R]
name[R]
transitions[R]
Public Class Methods
new(name, &block)
click to toggle source
Create an event object
@param name [Symbol] the name of the event @param block [Block] the block of code in the event
# File lib/finite/event.rb, line 12 def initialize(name, &block) @name = name @transitions = Hash.new @callbacks = {before: Array.new, after: Array.new} instance_eval &block end
Public Instance Methods
==(event)
click to toggle source
Are two events equal
@param event [Object] the object you are comparing it to @return true if they are equal false if not
# File lib/finite/event.rb, line 23 def ==(event) if event.is_a? Event @name == event.name elsif event.is_a? Symbol @name == event else false end end
inspect()
click to toggle source
Overridden for p
# File lib/finite/event.rb, line 39 def inspect @name end
to_s()
click to toggle source
Overridden for puts and print
# File lib/finite/event.rb, line 34 def to_s @name.to_s end
Private Instance Methods
go(opts)
click to toggle source
The transition method for the dsl
@param opts [Hash] the options for a transition
# File lib/finite/event.rb, line 47 def go(opts) options = [] if opts[:from].is_a? Array opts[:from].each do |from| options << {from: from, to: opts[:to]} end else options << opts end options.each do |opt| @transitions[opt[:from]] = Transition.new(opt) end end