Class: CollinsNotify::Configuration
- Inherits:
-
Object
- Object
- CollinsNotify::Configuration
- Includes:
- ConfigurationMixin
- Defined in:
- lib/collins_notify/configuration.rb
Instance Attribute Summary collapse
-
#adapters ⇒ Object
Returns the value of attribute adapters.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#config ⇒ Object
Override ConfigurationMixin#config.
-
#increase_verbosity ⇒ Object
Shorthand for severity assignment but silently fails if too verbose.
-
#initialize(logger, opts = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #message_body? ⇒ Boolean
- #original_to_hash ⇒ Object
- #resolved_template ⇒ Object
- #stdin? ⇒ Boolean
- #template? ⇒ Boolean
- #to_hash ⇒ Object
-
#valid? ⇒ Boolean
Override ConfigurationMixin#valid?.
Methods included from ConfigurationMixin
#debug?, #error?, #fatal?, #info?, #method_missing, #sevname, #test?, #trace?, #warn?
Constructor Details
#initialize(logger, opts = {}) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 |
# File 'lib/collins_notify/configuration.rb', line 9 def initialize logger, opts = {} @adapters = {} configurable.each do |key, value| instance_variable_set "@#{key.to_s}".to_sym, value end @logger = logger merge opts end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CollinsNotify::ConfigurationMixin
Instance Attribute Details
#adapters ⇒ Object
Returns the value of attribute adapters.
7 8 9 |
# File 'lib/collins_notify/configuration.rb', line 7 def adapters @adapters end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/collins_notify/configuration.rb', line 6 def logger @logger end |
Instance Method Details
#config ⇒ Object
Override ConfigurationMixin#config
19 20 21 |
# File 'lib/collins_notify/configuration.rb', line 19 def config self end |
#increase_verbosity ⇒ Object
Shorthand for severity assignment but silently fails if too verbose
39 40 41 42 43 44 45 46 |
# File 'lib/collins_notify/configuration.rb', line 39 def increase_verbosity if severity > -1 then self.severity -= 1 if trace? then $DEBUG = true end end end |
#message_body? ⇒ Boolean
48 49 50 |
# File 'lib/collins_notify/configuration.rb', line 48 def template? || stdin? end |
#original_to_hash ⇒ Object
71 |
# File 'lib/collins_notify/configuration.rb', line 71 alias_method :original_to_hash, :to_hash |
#resolved_template ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/collins_notify/configuration.rb', line 52 def resolved_template return nil unless template if File.exists?(File.(template)) then return File.(template) elsif template_dir && File.exists?(File.(File.join(template_dir, template))) then return File.(File.join(template_dir, template)) elsif File.exists?(File.(File.join(default_template_dir, template))) then return File.(File.join(default_template_dir, template)) end end |
#stdin? ⇒ Boolean
63 64 65 |
# File 'lib/collins_notify/configuration.rb', line 63 def stdin? !$stdin.tty? end |
#template? ⇒ Boolean
67 68 69 |
# File 'lib/collins_notify/configuration.rb', line 67 def template? !resolved_template.nil? end |
#to_hash ⇒ Object
72 73 74 |
# File 'lib/collins_notify/configuration.rb', line 72 def to_hash original_to_hash.merge(:severity_name => sevname, :adapters => adapters) end |
#valid? ⇒ Boolean
Override ConfigurationMixin#valid?
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/collins_notify/configuration.rb', line 24 def valid? adapters = CollinsNotify::Notifier.adapters.keys if type.nil? || !adapters.include?(type) then msg = "Invalid notifier type specified. Valid notifiers: #{adapters.sort.join(', ')}" logger.error msg return false end unless then logger.error "No message body found in specified template or stdin" return false end true end |