Class: Foreplay::Engine::Logger
- Inherits:
-
Object
- Object
- Foreplay::Engine::Logger
- Defined in:
- lib/foreplay/engine/logger.rb
Constant Summary collapse
- INDENT =
4- MARGIN =
24
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #formatted_message ⇒ Object
- #header ⇒ Object
- #header_content ⇒ Object
-
#initialize(m, o = {}) ⇒ Logger
constructor
A new instance of Logger.
- #margin ⇒ Object
- #margin_format ⇒ Object
- #margin_width ⇒ Object
- #output ⇒ Object
- #silent? ⇒ Boolean
Constructor Details
#initialize(m, o = {}) ⇒ Logger
Returns a new instance of Logger.
9 10 11 12 13 14 |
# File 'lib/foreplay/engine/logger.rb', line 9 def initialize(m, o = {}) = m = o output end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/foreplay/engine/logger.rb', line 7 def end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/foreplay/engine/logger.rb', line 7 def end |
Instance Method Details
#formatted_message ⇒ Object
20 21 22 23 24 25 |
# File 'lib/foreplay/engine/logger.rb', line 20 def ||= header + .gsub(/\A\s+/, '') .gsub(/\s+\z/, '') .gsub(/(\r\n|\r|\n)/, "\n#{margin}") end |
#header ⇒ Object
27 28 29 |
# File 'lib/foreplay/engine/logger.rb', line 27 def header @header ||= (margin_format % header_content[0, margin_width - 1]).white end |
#header_content ⇒ Object
31 32 33 |
# File 'lib/foreplay/engine/logger.rb', line 31 def header_content @header_content ||= ([:host] || '') end |
#margin ⇒ Object
35 36 37 |
# File 'lib/foreplay/engine/logger.rb', line 35 def margin @margin ||= margin_format % '' end |
#margin_format ⇒ Object
47 48 49 |
# File 'lib/foreplay/engine/logger.rb', line 47 def margin_format @margin_format ||= "%-#{margin_width}s" end |
#margin_width ⇒ Object
43 44 45 |
# File 'lib/foreplay/engine/logger.rb', line 43 def margin_width @margin_width ||= MARGIN + INDENT * ([:indent] || 0) end |
#output ⇒ Object
16 17 18 |
# File 'lib/foreplay/engine/logger.rb', line 16 def output puts unless silent? end |
#silent? ⇒ Boolean
39 40 41 |
# File 'lib/foreplay/engine/logger.rb', line 39 def silent? @silent ||= ([:silent] == true) || .blank? end |