Class: GorgService::Message::ErrorLog

Inherits:
Object
  • Object
show all
Defined in:
lib/gorg_service/message/error_log.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: "info", id: SecureRandom.uuid, sender: GorgService.configuration.application_id, message: "", timestamp: DateTime.now, debug: {}) ⇒ ErrorLog

Returns a new instance of ErrorLog.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gorg_service/message/error_log.rb', line 13

def initialize( type: "info",
                id: SecureRandom.uuid,
                sender: GorgService.configuration.application_id,
                message: "",
                timestamp: DateTime.now,
                debug: {})
  @type=type
  @id=id
  @sender=sender
  @message=message
  @timestamp=timestamp
  @debug=debug
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



11
12
13
# File 'lib/gorg_service/message/error_log.rb', line 11

def debug
  @debug
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/gorg_service/message/error_log.rb', line 11

def id
  @id
end

#messageObject

Returns the value of attribute message.



11
12
13
# File 'lib/gorg_service/message/error_log.rb', line 11

def message
  @message
end

#senderObject

Returns the value of attribute sender.



11
12
13
# File 'lib/gorg_service/message/error_log.rb', line 11

def sender
  @sender
end

#timestampObject

Returns the value of attribute timestamp.



11
12
13
# File 'lib/gorg_service/message/error_log.rb', line 11

def timestamp
  @timestamp
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/gorg_service/message/error_log.rb', line 11

def type
  @type
end

Class Method Details

.parse(obj) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gorg_service/message/error_log.rb', line 43

def parse(obj)
  obj=JSON.parse(obj) unless obj.is_a? Hash

  obj=convert_keys_to_sym(obj)

  self.new( type: obj[:error_type],
            id: obj[:error_uuid],
            sender: obj[:error_sender],
            message: obj[:error_message],
            timestamp: DateTime.parse(obj[:timestamp]),
            debug: obj[:error_debug])

end

Instance Method Details

#to_hObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/gorg_service/message/error_log.rb', line 27

def to_h
  h={"error_type" => type,
    "error_uuid" => id,
    "error_sender" => sender,
    "error_message" => message,
    "timestamp" => timestamp.iso8601,
    }
  h["error_debug"]= debug if debug
  h
end

#to_jsonObject



38
39
40
# File 'lib/gorg_service/message/error_log.rb', line 38

def to_json
  to_h.to_json
end