Sha256: 1d612ae94dc9b828478bde5d3c497ac9d15c3b36590db215eb27a6aedaf125b8
Contents?: true
Size: 1.07 KB
Versions: 11
Compression:
Stored size: 1.07 KB
Contents
module ChronoTrigger class ConfigurationException < Exception; end class Shell DEFAULT_TRIGGERS = "lib/triggers/*.rb" #Load triggers defined in the trigger files by evaluating them in the context of this Shell instance. def load_triggers(files = Dir.glob("#{DEFAULT_TRIGGERS}")) files.each { |file| self.instance_eval(File.read(file), file) } end #Instantiate a trigger and evaluate the passed in block in the context of the trigger. #This is the initial method call when setting up a configuration using the DSL. def trigger(name, &block) raise ConfigurationException.new("No configuration specified for trigger #{name}") unless block_given? trigger = Trigger.new(name) trigger.instance_eval(&block) triggers << trigger trigger end #Run execute on any trigger who's cron entry matches the current time. def execute_triggers now = Time.now triggers.map {|trigger| trigger.execute_on_match(now)} end def triggers @triggers ||= [] end end end
Version data entries
11 entries across 11 versions & 2 rubygems