Module: DogWatch::Model::Mixin::Colorize

Included in:
Response
Defined in:
lib/dogwatch/model/mixin/colorize.rb

Overview

Provides a colorize() mixin that handles shell output coloring

Instance Method Summary collapse

Instance Method Details

#colorize(param, options = {}) ⇒ Symbol

Parameters:

  • param (Symbol)
  • options (Hash) (defaults to: {})

Returns:

  • (Symbol)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dogwatch/model/mixin/colorize.rb', line 11

def colorize(param, options = {})
  define_method(:color) do
    case instance_variable_get("@#{ param }")
    when *options.fetch(:white, [:status]) then :white
    when *options.fetch(:cyan, [:debug, :trace]) then :cyan
    when *options.fetch(:green, [:info, :success, :create]) then :green
    when *options.fetch(:yellow, [:warn, :update]) then :yellow
    when *options.fetch(:red, [:error, :fail, :delete]) then :red
    else options.fetch(:default, :green)
    end
  end
end