Class: Clacks::Configurator
- Inherits:
-
Object
- Object
- Clacks::Configurator
- Defined in:
- lib/clacks/configurator.rb
Constant Summary collapse
- DEFAULTS =
{ :poll_interval => 60, :logger => Logger.new($stderr).tap { |logger| logger.level = Logger::INFO }, :on_mail => lambda { |mail| Clacks.logger.info("Mail from #{mail.from.first}, subject: #{mail.subject}") } }
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#map ⇒ Object
Returns the value of attribute map.
Instance Method Summary collapse
-
#[](key) ⇒ Object
:nodoc:.
- #after_initialize(*args, &block) ⇒ Object
- #find_options(hash) ⇒ Object
- #imap(hash) ⇒ Object
-
#initialize(config_file = nil) ⇒ Configurator
constructor
A new instance of Configurator.
-
#logger(obj) ⇒ Object
Sets the Logger-like object.
- #on_mail(*args, &block) ⇒ Object
- #pid(path) ⇒ Object
- #poll_interval(value) ⇒ Object
- #pop3(hash) ⇒ Object
-
#stderr_path(path) ⇒ Object
If you’re running Clacks daemonized, then you must specify a path to prevent error messages from going to /dev/null.
-
#stdout_path(path) ⇒ Object
If you’re running Clacks daemonized, then you must specify a path to prevent error messages from going to /dev/null.
Constructor Details
#initialize(config_file = nil) ⇒ Configurator
Returns a new instance of Configurator.
14 15 16 17 18 19 |
# File 'lib/clacks/configurator.rb', line 14 def initialize(config_file = nil) self.map = Hash.new map.merge!(DEFAULTS) self.config_file = config_file instance_eval(File.read(config_file), config_file) if config_file end |
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
4 5 6 |
# File 'lib/clacks/configurator.rb', line 4 def config_file @config_file end |
#map ⇒ Object
Returns the value of attribute map.
4 5 6 |
# File 'lib/clacks/configurator.rb', line 4 def map @map end |
Instance Method Details
#[](key) ⇒ Object
:nodoc:
21 22 23 |
# File 'lib/clacks/configurator.rb', line 21 def [](key) # :nodoc: map[key] end |
#after_initialize(*args, &block) ⇒ Object
73 74 75 |
# File 'lib/clacks/configurator.rb', line 73 def after_initialize(*args, &block) set_hook(:after_initialize, 0, block_given? ? block : args[0]) end |
#find_options(hash) ⇒ Object
65 66 67 |
# File 'lib/clacks/configurator.rb', line 65 def (hash) set_hash(:find_options, hash) end |
#imap(hash) ⇒ Object
61 62 63 |
# File 'lib/clacks/configurator.rb', line 61 def imap(hash) set_hash(:imap, hash) end |
#logger(obj) ⇒ Object
Sets the Logger-like object. The default Logger will log its output to Rails.logger if you’re running within a rails environment, otherwise it will output to the path specified by stdout_path
.
37 38 39 40 41 42 43 |
# File 'lib/clacks/configurator.rb', line 37 def logger(obj) %w(debug info warn error fatal level).each do |m| next if obj.respond_to?(m) raise ArgumentError, "logger #{obj} does not respond to method #{m}" end map[:logger] = obj end |
#on_mail(*args, &block) ⇒ Object
69 70 71 |
# File 'lib/clacks/configurator.rb', line 69 def on_mail(*args, &block) set_hook(:on_mail, 1, block_given? ? block : args[0]) end |
#pid(path) ⇒ Object
29 30 31 |
# File 'lib/clacks/configurator.rb', line 29 def pid(path) set_path(:pid, path) end |
#poll_interval(value) ⇒ Object
25 26 27 |
# File 'lib/clacks/configurator.rb', line 25 def poll_interval(value) map[:poll_interval] = value.to_i end |
#pop3(hash) ⇒ Object
57 58 59 |
# File 'lib/clacks/configurator.rb', line 57 def pop3(hash) set_hash(:pop3, hash) end |
#stderr_path(path) ⇒ Object
If you’re running Clacks daemonized, then you must specify a path to prevent error messages from going to /dev/null.
53 54 55 |
# File 'lib/clacks/configurator.rb', line 53 def stderr_path(path) set_path(:stderr_path, path) end |
#stdout_path(path) ⇒ Object
If you’re running Clacks daemonized, then you must specify a path to prevent error messages from going to /dev/null.
47 48 49 |
# File 'lib/clacks/configurator.rb', line 47 def stdout_path(path) set_path(:stdout_path, path) end |