Sha256: 9e7be483bddb605cbf8fb14ce38f59c34dd85d26082717e65ce6977b272a9a97

Contents?: true

Size: 857 Bytes

Versions: 3

Compression:

Stored size: 857 Bytes

Contents

module DogWatch
  module Model
    module Mixin
      ##
      # Provides a colorize() mixin that handles shell output coloring
      ##
      module Colorize
        # @param [Symbol] param
        # @param [Hash] options
        # @return [Symbol]
        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
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dogwatch-1.2.0 lib/dogwatch/model/mixin/colorize.rb
dogwatch-1.1.1 lib/dogwatch/model/mixin/colorize.rb
dogwatch-1.1.0 lib/dogwatch/model/mixin/colorize.rb