class Thyme::HooksPlugin

Generic plugin for users to run Ruby code in Thyme event callbacks in thymerc

Public Class Methods

new(config) click to toggle source
# File lib/thyme/hooks_plugin.rb, line 4
def initialize(config)
  @config = config
  @hooks = {before_all: [], before: [], tick: [], after: [], after_all: []}
end

Public Instance Methods

add(type, &block) click to toggle source
# File lib/thyme/hooks_plugin.rb, line 9
def add(type, &block)
  @hooks[type] << block
end
after(seconds_left) click to toggle source
# File lib/thyme/hooks_plugin.rb, line 25
def after(seconds_left)
  @hooks[:after].each { |a| @config.instance_exec(seconds_left, &a) }
end
after_all() click to toggle source
# File lib/thyme/hooks_plugin.rb, line 29
def after_all
  @hooks[:after_all].each { |a| @config.instance_exec(&a) }
end
before() click to toggle source
# File lib/thyme/hooks_plugin.rb, line 17
def before
  @hooks[:before].each { |b| @config.instance_exec(&b) }
end
before_all() click to toggle source
# File lib/thyme/hooks_plugin.rb, line 13
def before_all
  @hooks[:before_all].each { |b| @config.instance_exec(&b) }
end
tick(seconds_left) click to toggle source
# File lib/thyme/hooks_plugin.rb, line 21
def tick(seconds_left)
  @hooks[:tick].each { |t| @config.instance_exec(seconds_left, &t) }
end