Class: Chef::Knife::ChopUI
- Includes:
- ChopErrors
- Defined in:
- lib/chef/knife/chop/ui.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #err(message) ⇒ Object
-
#error(message) ⇒ Object
Print an error message.
-
#fatal(message) ⇒ Object
Print a message describing a fatal error.
-
#info(message) ⇒ Object
def define_ui_methods() class << self ::Logging::LEVELS.each{|name,level| code = <<-CODE def #{name}(str) msg(str) end CODE self.class.class_eval(code,__FILE__,__LINE__) } end end.
-
#initialize(logger, config) ⇒ ChopUI
constructor
A new instance of ChopUI.
- #method_missing(name, *args, &block) ⇒ Object
-
#msg(message) ⇒ Object
def define_log_methods( ui ).
- #shifted(name) ⇒ Object
- #step(message) ⇒ Object
-
#warn(message) ⇒ Object
Print a warning message.
Constructor Details
#initialize(logger, config) ⇒ ChopUI
Returns a new instance of ChopUI.
29 30 31 32 33 |
# File 'lib/chef/knife/chop/ui.rb', line 29 def initialize(logger, config) super($stdout, $stderr, $stdin, config) @logger = logger #define_ui_methods() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
82 83 84 85 86 |
# File 'lib/chef/knife/chop/ui.rb', line 82 def method_missing(name, *args, &block) msg = "#{self.class.name}: Method missing: #{name}" @logger.fatal(msg) raise ChopInternalError.new(msg) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
27 28 29 |
# File 'lib/chef/knife/chop/ui.rb', line 27 def logger @logger end |
Instance Method Details
#err(message) ⇒ Object
63 64 65 |
# File 'lib/chef/knife/chop/ui.rb', line 63 def err() error() end |
#error(message) ⇒ Object
Print an error message
73 74 75 |
# File 'lib/chef/knife/chop/ui.rb', line 73 def error() msg() end |
#fatal(message) ⇒ Object
Print a message describing a fatal error.
78 79 80 |
# File 'lib/chef/knife/chop/ui.rb', line 78 def fatal() msg() end |
#info(message) ⇒ Object
def define_ui_methods()
class << self
::Logging::LEVELS.each{|name,level|
code = <<-CODE
def #{name}(str)
msg(str)
end
CODE
self.class.class_eval(code,__FILE__,__LINE__)
}
end
end
55 56 57 |
# File 'lib/chef/knife/chop/ui.rb', line 55 def info() msg() end |
#msg(message) ⇒ Object
def define_log_methods( ui )
36 37 38 39 40 41 |
# File 'lib/chef/knife/chop/ui.rb', line 36 def msg() caller = Kernel.caller[0] match = caller.match(%r/([-\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o) name = shifted(match[3]) @logger.send(name, ) end |
#shifted(name) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/chef/knife/chop/ui.rb', line 88 def shifted(name) name = 'info' unless ::Logging::LEVELS.has_key?(name) num = ::Logging::LEVELS[name]+1 case name when 'todo' 'error' when 'err' 'error' # when 'info' # 'debug' when 'debug' 'trace' else name end end |
#step(message) ⇒ Object
59 60 61 |
# File 'lib/chef/knife/chop/ui.rb', line 59 def step() msg() end |
#warn(message) ⇒ Object
Print a warning message
68 69 70 |
# File 'lib/chef/knife/chop/ui.rb', line 68 def warn() msg() end |