Module: God::Configurable
Class Method Summary collapse
-
.complain(text, configurable = nil) ⇒ Object
configurable - Should respond to :watch and :friendly_name.
Instance Method Summary collapse
- #base_name ⇒ Object
- #complain(text, configurable = nil) ⇒ Object
- #friendly_name ⇒ Object
-
#prepare ⇒ Object
Override this method in your Configurable (optional).
- #reset ⇒ Object
-
#valid? ⇒ Boolean
Override this method in your Configurable (optional).
Class Method Details
.complain(text, configurable = nil) ⇒ Object
configurable - Should respond to :watch and :friendly_name
41 42 43 44 45 46 47 48 49 |
# File 'lib/god/configurable.rb', line 41 def self.complain(text, configurable = nil) watch = configurable.watch rescue nil msg = '' msg += "#{watch.name}: " if watch msg += text msg += " for #{configurable.friendly_name}" if configurable applog(watch, :error, msg) false end |
Instance Method Details
#base_name ⇒ Object
32 33 34 |
# File 'lib/god/configurable.rb', line 32 def base_name @base_name ||= self.class.name.split('::').last end |
#complain(text, configurable = nil) ⇒ Object
51 52 53 |
# File 'lib/god/configurable.rb', line 51 def complain(text, configurable = nil) Configurable.complain(text, configurable) end |
#friendly_name ⇒ Object
36 37 38 |
# File 'lib/god/configurable.rb', line 36 def friendly_name base_name end |
#prepare ⇒ Object
Override this method in your Configurable (optional)
Called once after the Configurable has been sent to the block and attributes have been set. Do any post-processing on attributes here
9 10 |
# File 'lib/god/configurable.rb', line 9 def prepare end |
#reset ⇒ Object
12 13 |
# File 'lib/god/configurable.rb', line 12 def reset end |
#valid? ⇒ Boolean
Override this method in your Configurable (optional)
Called once during evaluation of the config file. Return true if valid, false otherwise
A convenience method ‘complain’ is available that will print out a message and return false, making it easy to report multiple validation errors:
def valid?
valid = true
valid &= complain("You must specify the 'pid_file' attribute for :memory_usage") if self.pid_file.nil?
valid &= complain("You must specify the 'above' attribute for :memory_usage") if self.above.nil?
valid
end
28 29 30 |
# File 'lib/god/configurable.rb', line 28 def valid? true end |