Class: Ghaki::Logger::Wrapper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ghaki/logger/wrapper/base.rb

Overview

Base wrapping logging class.

Direct Known Subclasses

Major, Minor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



13
14
15
# File 'lib/ghaki/logger/wrapper/base.rb', line 13

def initialize opts={}
  @logger = opts[:logger]
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/ghaki/logger/wrapper/base.rb', line 11

def logger
  @logger
end

Instance Method Details

#began(msg) ⇒ Object

Print a processing begins info message.



19
20
# File 'lib/ghaki/logger/wrapper/base.rb', line 19

def began msg
end

#ended(msg) ⇒ Object

Print a processing ends info message.



24
25
# File 'lib/ghaki/logger/wrapper/base.rb', line 24

def ended msg
end

#step(msg) ⇒ Object

Print a processing step info message.



29
30
# File 'lib/ghaki/logger/wrapper/base.rb', line 29

def step msg
end

#wrap(msg, &block) ⇒ Object

Wrap a code block with begin / end messages. End message will not be printed if an exception is reached.



35
36
37
38
39
40
# File 'lib/ghaki/logger/wrapper/base.rb', line 35

def wrap msg, &block
  self.began msg
  out = block.call
  self.ended msg
  out
end

#wrap!(msg, &block) ⇒ Object

Wrap a code block with begin / end messages. End message will be printed if an exception is reached.



45
46
47
48
49
50
# File 'lib/ghaki/logger/wrapper/base.rb', line 45

def wrap! msg, &block
  self.began msg
  block.call
ensure
  self.ended msg
end

#wrap_if(check, msg, &block) ⇒ Object

Wrap a code block with a begin/end message, unless the check evaluates as false. If the check is false, print a skipping step info log message. End message will not be printed if an exception is reached.



56
57
58
59
60
61
62
# File 'lib/ghaki/logger/wrapper/base.rb', line 56

def wrap_if check, msg, &block
  if check
    self.wrap msg, &block
  else
    self.step msg + ' - skipping'
  end
end

#wrap_if!(check, msg, &block) ⇒ Object

Wrap a code block with a begin/end message, unless the check evaluates as false. If the check is false, print a skipping step info log message. End message will be printed if an exception is reached.



68
69
70
71
72
73
74
# File 'lib/ghaki/logger/wrapper/base.rb', line 68

def wrap_if! check, msg, &block
  if check
    self.wrap! msg, &block
  else
    self.step msg + ' - skipping'
  end
end