class Thyme::Config
Configure state for the application. This can be done via the thymerc file or CLI flags. Public methods in this file are exposed to the thymerc file.
Constants
- CONFIG_FILE
- OPTIONS
- PID_FILE
- TMUX_FILE
Attributes
break[RW]
daemon[RW]
optparse[RW]
repeat[RW]
repeat_index[RW]
Public Class Methods
new()
click to toggle source
# File lib/thyme/config.rb, line 12 def initialize # options set via config file @break_color = 'default' @default_color = 'default' @interval = 1 @timer = 25 * 60 @timer_break = 5 * 60 @tmux = false @tmux_theme = "#[default]#[fg=%s]%s#[default]" @warning = 5 * 60 @warning_color = 'red,bold' # plugins set via config file @plugins = [] @hooks_plugin = use(Thyme::HooksPlugin) # settings via command line @break = false @daemon = false @repeat = 1 @repeat_index = 1 end
Public Instance Methods
after(kind = :each, &block)
click to toggle source
# File lib/thyme/config.rb, line 51 def after(kind = :each, &block) type = kind == :all ? :after_all : :after @hooks_plugin.add(type, &block) end
before(kind = :each, &block)
click to toggle source
# File lib/thyme/config.rb, line 46 def before(kind = :each, &block) type = kind == :all ? :before_all : :before @hooks_plugin.add(type, &block) end
option(short, long, desc, &block)
click to toggle source
# File lib/thyme/config.rb, line 60 def option(short, long, desc, &block) return if !@optparse @optparse.on("-#{short}", "--#{long}", desc) do |*args| self.instance_exec(*args, &block) exit if !@run end end
send_to_plugin(message, *args)
click to toggle source
# File lib/thyme/config.rb, line 68 def send_to_plugin(message, *args) @plugins.each do |plugin| begin plugin.public_send(message, *args) if plugin.respond_to?(message) rescue $stderr.puts "Exception raised from #{plugin.class}:", $!, $@ end end end
set(opt, val)
click to toggle source
# File lib/thyme/config.rb, line 35 def set(opt, val) raise Thyme::Error.new("Invalid option: #{opt}") if !OPTIONS.include?(opt.to_sym) self.instance_variable_set("@#{opt}", val) end
tick(&block)
click to toggle source
# File lib/thyme/config.rb, line 56 def tick(&block) @hooks_plugin.add(:tick, &block) end
use(plugin_class, *args, &block)
click to toggle source
# File lib/thyme/config.rb, line 40 def use(plugin_class, *args, &block) plugin = plugin_class.new(self, *args, &block) @plugins << plugin plugin end