Class: Compass::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/compass/logger.rb

Constant Summary collapse

DEFAULT_ACTIONS =
[:directory, :exists, :remove, :create, :overwrite, :compile]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*actions) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
12
# File 'lib/compass/logger.rb', line 8

def initialize(*actions)
  self.options = actions.last.is_a?(Hash) ? actions.pop : {}
  @actions = DEFAULT_ACTIONS.dup
  @actions += actions
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



6
7
8
# File 'lib/compass/logger.rb', line 6

def actions
  @actions
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/compass/logger.rb', line 6

def options
  @options
end

Instance Method Details

#action_padding(action) ⇒ Object

add padding to the left of an action that was performed.



25
26
27
# File 'lib/compass/logger.rb', line 25

def action_padding(action)
  ' ' * [(max_action_length - action.to_s.length), 0].max
end

#log(msg) ⇒ Object

Emit a log message



20
21
22
# File 'lib/compass/logger.rb', line 20

def log(msg)
  puts msg
end

#max_action_lengthObject

the maximum length of all the actions known to the logger.



30
31
32
# File 'lib/compass/logger.rb', line 30

def max_action_length
  @max_action_length ||= actions.inject(0){|memo, a| [memo, a.to_s.length].max}
end

#record(action, *arguments) ⇒ Object

Record an action that has occurred



15
16
17
# File 'lib/compass/logger.rb', line 15

def record(action, *arguments)
  log "#{action_padding(action)}#{action} #{arguments.join(' ')}"
end