Class: ChronoTrigger::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/chrono_trigger/shell.rb

Constant Summary collapse

DEFAULT_TRIGGERS =
"lib/triggers/*.rb"

Instance Method Summary collapse

Instance Method Details

#execute_triggersObject

Run execute on any trigger who’s cron entry matches the current time.



26
27
28
29
# File 'lib/chrono_trigger/shell.rb', line 26

def execute_triggers
  now = Time.now
  triggers.map {|trigger| trigger.execute_on_match(now)}
end

#load_triggers(files = Dir.glob("#{DEFAULT_TRIGGERS}")) ⇒ Object

Load triggers defined in the trigger files by evaluating them in the context of this Shell instance.



9
10
11
# File 'lib/chrono_trigger/shell.rb', line 9

def load_triggers(files = Dir.glob("#{DEFAULT_TRIGGERS}"))
  files.each { |file| self.instance_eval(File.read(file), file) }
end

#trigger(name, &block) ⇒ Object

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.



15
16
17
18
19
20
21
22
23
# File 'lib/chrono_trigger/shell.rb', line 15

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

#triggersObject



31
32
33
# File 'lib/chrono_trigger/shell.rb', line 31

def triggers
  @triggers ||= []
end