Module: Convection::Model::Mixin::Colorize

Included in:
Diff, Event
Defined in:
lib/convection/model/mixin/colorize.rb

Instance Method Summary collapse

Instance Method Details

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



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/convection/model/mixin/colorize.rb', line 5

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