class Eye::Trigger
Constants
- TYPES
Attributes
message[R]
options[R]
process[R]
Public Class Methods
create(process, options = {})
click to toggle source
# File lib/eye/trigger.rb, line 35 def self.create(process, options = {}) get_class(options[:type]).new(process, options) rescue Exception, Timeout::Error => ex log_ex(ex) nil end
get_class(type)
click to toggle source
# File lib/eye/trigger.rb, line 26 def self.get_class(type) klass = eval("Eye::Trigger::#{TYPES[type]}") rescue nil raise "unknown trigger #{type}" unless klass if deps = klass.requires Array(deps).each { |d| require d } end klass end
name_and_class(type)
click to toggle source
# File lib/eye/trigger.rb, line 16 def self.name_and_class(type) type = type.to_sym return {:name => type, :type => type} if TYPES[type] if type =~ /\A(.*?)_?[0-9]+\z/ ctype = $1.to_sym return {:name => type, :type => ctype} if TYPES[ctype] end end
new(process, options = {})
click to toggle source
# File lib/eye/trigger.rb, line 47 def initialize(process, options = {}) @options = options @process = process @full_name = @process.full_name if @process debug "add #{options}" end
register(base)
click to toggle source
# File lib/eye/trigger.rb, line 106 def self.register(base) name = base.to_s.gsub('Eye::Trigger::', '') type = name.underscore.to_sym Eye::Trigger::TYPES[type] = name Eye::Trigger.const_set(name, base) end
requires()
click to toggle source
# File lib/eye/trigger.rb, line 113 def self.requires end
validate!(options = {})
click to toggle source
# File lib/eye/trigger.rb, line 43 def self.validate!(options = {}) get_class(options[:type]).validate(options) end
Public Instance Methods
check(transition)
click to toggle source
# File lib/eye/trigger.rb, line 94 def check(transition) raise NotImplementedError end
defer(&block)
click to toggle source
# File lib/eye/trigger.rb, line 102 def defer(&block) Celluloid::Future.new(&block).value end
filter_transition(trans)
click to toggle source
# File lib/eye/trigger.rb, line 86 def filter_transition(trans) return true unless to || from || event compare_state(trans.to_name, to) && compare_state(trans.from_name, from) && compare_state(trans.event, event) end
inspect()
click to toggle source
# File lib/eye/trigger.rb, line 55 def inspect "<#{self.class} @process='#{@full_name}' @options=#{@options}>" end
logger_sub_tag()
click to toggle source
# File lib/eye/trigger.rb, line 63 def logger_sub_tag "trigger(#{@options[:type]})" end
logger_tag()
click to toggle source
# File lib/eye/trigger.rb, line 59 def logger_tag @process.logger.prefix end
notify(transition, reason)
click to toggle source
# File lib/eye/trigger.rb, line 67 def notify(transition, reason) debug "check (:#{transition.event}) :#{transition.from} => :#{transition.to}" @reason = reason @transition = transition check(transition) if filter_transition(transition) rescue Exception, Timeout::Error => ex if ex.class == Eye::Process::StateError raise ex else log_ex(ex) end end
run_in_process_context(p)
click to toggle source
# File lib/eye/trigger.rb, line 98 def run_in_process_context(p) process.instance_exec(&p) if process.alive? end
Private Instance Methods
compare_state(state_name, condition)
click to toggle source
# File lib/eye/trigger.rb, line 125 def compare_state(state_name, condition) case condition when Symbol state_name == condition when Array condition.include?(state_name) else true end end