Sha256: b2c22561f0dcc30b34fd60eead5b45de3c7492e2b8c544305f7660ced6cab712

Contents?: true

Size: 980 Bytes

Versions: 42

Compression:

Stored size: 980 Bytes

Contents

module Compass
  class Logger

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

    attr_accessor :actions, :options

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

    # Record an action that has occurred
    def record(action, *arguments)
      log "#{action_padding(action)}#{action} #{arguments.join(' ')}"
    end

    # Emit a log message
    def log(msg)
      puts msg
    end

    # add padding to the left of an action that was performed.
    def action_padding(action)
      ' ' * [(max_action_length - action.to_s.length), 0].max
    end

    # the maximum length of all the actions known to the logger.
    def max_action_length
      @max_action_length ||= actions.inject(0){|memo, a| [memo, a.to_s.length].max}
    end
  end

  class NullLogger
    def record(*args)
    end

    def log(msg)
    end
  end
end

Version data entries

42 entries across 42 versions & 5 rubygems

Version Path
alphasights-compass-0.8.12 lib/compass/logger.rb
chriseppstein-compass-0.6.10 lib/compass/logger.rb
chriseppstein-compass-0.6.11 lib/compass/logger.rb
chriseppstein-compass-0.6.12 lib/compass/logger.rb
chriseppstein-compass-0.6.13 lib/compass/logger.rb
chriseppstein-compass-0.6.14 lib/compass/logger.rb
chriseppstein-compass-0.6.15 lib/compass/logger.rb
chriseppstein-compass-0.6.6 lib/compass/logger.rb
chriseppstein-compass-0.6.7 lib/compass/logger.rb
chriseppstein-compass-0.6.8 lib/compass/logger.rb
chriseppstein-compass-0.6.9 lib/compass/logger.rb
chriseppstein-compass-0.7.0 lib/compass/logger.rb
chriseppstein-compass-0.8.0 lib/compass/logger.rb
chriseppstein-compass-0.8.1 lib/compass/logger.rb
chriseppstein-compass-0.8.10 lib/compass/logger.rb
chriseppstein-compass-0.8.11 lib/compass/logger.rb
chriseppstein-compass-0.8.12 lib/compass/logger.rb
chriseppstein-compass-0.8.13 lib/compass/logger.rb
chriseppstein-compass-0.8.14 lib/compass/logger.rb
chriseppstein-compass-0.8.15 lib/compass/logger.rb