Sha256: 14b92ae41b755d955bf12e4d792184f57697ffd35eed4d9e78bd4d9b6c19e1a0

Contents?: true

Size: 588 Bytes

Versions: 1

Compression:

Stored size: 588 Bytes

Contents

module Twiglet
  class Message < Hash
    def initialize(msg)
      super
      case msg
      when String
        self[:message] = msg
      when Hash
        replace(msg.transform_keys!(&:to_sym))
      else
        super(msg)
      end

      validate!
    end

    private

    def validate!
      raise 'Message must be initialized with a String or a non-empty Hash' if empty?

      raise 'Log object must have a \'message\' property' unless self[:message]

      raise 'The \'message\' property of the log object must not be empty' if self[:message].strip.empty?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twiglet-3.0.8 lib/twiglet/message.rb