Sha256: ec06cb45631b15bd2655b7e547ab798a27d9af0b6e9f8698726ab495be04d84b
Contents?: true
Size: 1.4 KB
Versions: 31
Compression:
Stored size: 1.4 KB
Contents
require "timber/events/controller_call" require "timber/events/custom" require "timber/events/exception" require "timber/events/http_client_request" require "timber/events/http_client_response" require "timber/events/http_server_request" require "timber/events/http_server_response" require "timber/events/sql_query" require "timber/events/template_render" module Timber # Namespace for all Timber supported events. module Events # Protocol for casting objects into a `Timber::Event`. # # @example Casting a hash # Timber::Events.build({type: :custom_event, message: "My log message", data: {my: "data"}}) def self.build(obj) if obj.is_a?(::Timber::Event) obj elsif obj.respond_to?(:to_timber_event) obj.to_timber_event elsif obj.is_a?(Hash) && obj.key?(:message) && obj.length == 2 event = obj.select { |k,v| k != :message } type = event.keys.first data = event.values.first Events::Custom.new( type: type, message: obj[:message], data: data ) elsif obj.is_a?(Struct) && obj.respond_to?(:message) && obj.respond_to?(:type) Events::Custom.new( type: obj.type, message: obj.message, data: obj.respond_to?(:to_h) ? obj.to_h : Timber::Util::Struct.to_hash(obj) # ruby 1.9.3 does not have to_h :( ) else nil end end end end
Version data entries
31 entries across 31 versions & 1 rubygems