lib/cyclone_lariat/abstract/message.rb in cyclone_lariat-0.3.10 vs lib/cyclone_lariat/abstract/message.rb in cyclone_lariat-0.4.0

- old
+ new

@@ -4,14 +4,14 @@ require_relative '../errors' module CycloneLariat module Abstract class Message < LunaPark::Entities::Attributable - attr :uuid, String, :new - attr :publisher, String, :new - attr :type, String, :new - attrs :client_error, :version, :data, + attr :uuid, String, :new + attr :publisher, String, :new + attr :type, String, :new + attrs :client_error, :version, :data, :request_id, :sent_at, :processed_at, :received_at def kind raise LunaPark::Errors::AbstractMethod end @@ -30,10 +30,14 @@ def processed_at=(value) @processed_at = wrap_time(value) end + def request_at=(value) + @request_id = wrap_string(value) + end + def processed? !@processed_at.nil? end def client_error_message=(txt) @@ -62,19 +66,30 @@ processed_at.to_i == other.processed_at.to_i end def to_json(*args) hash = serialize - hash[:type] = [kind, hash[:type]].join '_' + hash[:type] = [kind, hash[:type]].join '_' + hash[:sent_at] = hash[:sent_at].iso8601(3) if hash[:sent_at] + hash[:received_at] = hash[:received_at].iso8601(3) if hash[:received_at] + hash[:processed_at] = hash[:processed_at].iso8601(3) if hash[:processed_at] hash.to_json(*args) end private def wrap_time(value) case value when String then Time.parse(value) when Time then value + when NilClass then nil + else raise ArgumentError, "Unknown type `#{value.class}`" + end + end + + def wrap_string(value) + case value + when String then String(value) when NilClass then nil else raise ArgumentError, "Unknown type `#{value.class}`" end end end