class Statesmin::Callback
Attributes
callback[R]
from[R]
to[R]
Public Class Methods
new(options = { from: nil, to: nil, callback: nil })
click to toggle source
# File lib/statesmin/callback.rb, line 9 def initialize(options = { from: nil, to: nil, callback: nil }) unless options[:callback].respond_to?(:call) raise InvalidCallbackError, "No callback passed" end @from = options[:from] @to = Array(options[:to]) @callback = options[:callback] end
Public Instance Methods
applies_to?(options = { from: nil, to: nil })
click to toggle source
# File lib/statesmin/callback.rb, line 23 def applies_to?(options = { from: nil, to: nil }) matches(options[:from], options[:to]) end
call(*args)
click to toggle source
# File lib/statesmin/callback.rb, line 19 def call(*args) callback.call(*args) end
Private Instance Methods
matches(from, to)
click to toggle source
# File lib/statesmin/callback.rb, line 29 def matches(from, to) matches_all_transitions || matches_to_state(from, to) || matches_from_state(from, to) || matches_both_states(from, to) end
matches_all_transitions()
click to toggle source
# File lib/statesmin/callback.rb, line 36 def matches_all_transitions from.nil? && to.empty? end
matches_both_states(from, to)
click to toggle source
# File lib/statesmin/callback.rb, line 48 def matches_both_states(from, to) from == self.from && self.to.include?(to) end
matches_from_state(from, to)
click to toggle source
# File lib/statesmin/callback.rb, line 40 def matches_from_state(from, to) (from == self.from && (to.nil? || self.to.empty?)) end
matches_to_state(from, to)
click to toggle source
# File lib/statesmin/callback.rb, line 44 def matches_to_state(from, to) ((from.nil? || self.from.nil?) && self.to.include?(to)) end