Class: Messaging::Message::FromJson
- Inherits:
-
Object
- Object
- Messaging::Message::FromJson
- Defined in:
- lib/messaging/message/from_json.rb
Class Method Summary collapse
Instance Method Summary collapse
- #empty_message ⇒ Object
-
#initialize(json) ⇒ FromJson
constructor
A new instance of FromJson.
- #message_class_from_name(message_name) ⇒ Object
- #new_without_defaults(attributes) ⇒ Object
- #to_message ⇒ Object
Constructor Details
#initialize(json) ⇒ FromJson
Returns a new instance of FromJson.
9 10 11 12 |
# File 'lib/messaging/message/from_json.rb', line 9 def initialize(json) @attributes = JSON.parse(json, symbolize_names: true) @klass = (@attributes[:message_name]) end |
Class Method Details
.call(json) ⇒ Object
5 6 7 |
# File 'lib/messaging/message/from_json.rb', line 5 def self.call(json) new(json). end |
Instance Method Details
#empty_message ⇒ Object
14 15 16 |
# File 'lib/messaging/message/from_json.rb', line 14 def Hash[@klass.attribute_set.map { |a| [a.name, nil] }] end |
#message_class_from_name(message_name) ⇒ Object
26 27 28 |
# File 'lib/messaging/message/from_json.rb', line 26 def () "::#{.camelize}".constantize end |
#new_without_defaults(attributes) ⇒ Object
18 19 20 |
# File 'lib/messaging/message/from_json.rb', line 18 def new_without_defaults(attributes) @klass.new(.merge(attributes)) end |
#to_message ⇒ Object
22 23 24 |
# File 'lib/messaging/message/from_json.rb', line 22 def new_without_defaults(@attributes) end |