Module: Sidekick::Actions::Triggers

Defined in:
lib/sidekick/actions/triggers.rb

Overview

Basically, the job of a trigger definition is to take the parameters and the block from a directive in the ‘.sidekick` file, and then hook into EventMachine in some way to set up the trigger.

Instance Method Summary collapse

Instance Method Details

#after(duration) ⇒ Object



26
27
28
29
30
31
# File 'lib/sidekick/actions/triggers.rb', line 26

def after(duration)
  EventMachine::Timer.new(duration) do
    log_trigger "after #{duration} seconds"
    yield
  end
end

#every(duration) ⇒ Object



19
20
21
22
23
24
# File 'lib/sidekick/actions/triggers.rb', line 19

def every(duration)
  EventMachine::PeriodicTimer.new(duration) do
    log_trigger "every #{duration} seconds"
    yield
  end
end

#on_start(&blk) ⇒ Object



33
34
35
# File 'lib/sidekick/actions/triggers.rb', line 33

def on_start(&blk)
  after(0, &blk)
end

#on_stop(&blk) ⇒ Object



37
38
39
# File 'lib/sidekick/actions/triggers.rb', line 37

def on_stop(&blk)
  ::Sidekick::STOP_CALLBACKS << blk
end

#watch(*globs) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sidekick/actions/triggers.rb', line 6

def watch(*globs)
  needs 'em-dir-watcher', 'to watch file changes'

  EMDirWatcher.watch(
    File.expand_path('.'),
    :include_only => globs,
    :grace_period => 0.2
    ) do |paths|
    log_trigger "watch #{paths.inspect}"
    yield(paths)
  end
end