Class: MmJsonClient::GenericType
- Inherits:
-
Object
- Object
- MmJsonClient::GenericType
- Defined in:
- lib/mm_json_client/generic_type.rb
Overview
The base class for dynamically generated types.
Class Method Summary collapse
Instance Method Summary collapse
- #deep_copy ⇒ Object
-
#initialize(attributes = {}) ⇒ GenericType
constructor
A new instance of GenericType.
- #set_properties ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ GenericType
Returns a new instance of GenericType.
4 5 6 7 8 9 |
# File 'lib/mm_json_client/generic_type.rb', line 4 def initialize(attributes = {}) @data = {} attributes.each do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end end |
Class Method Details
.property(attribute) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mm_json_client/generic_type.rb', line 12 def property(attribute) class_eval do define_method(attribute) do @data[attribute] end define_method("#{attribute}=") do |value| @data[attribute] = value end end end |
Instance Method Details
#deep_copy ⇒ Object
33 34 35 |
# File 'lib/mm_json_client/generic_type.rb', line 33 def deep_copy Marshal.load(Marshal.dump(self)) end |
#set_properties ⇒ Object
25 26 27 |
# File 'lib/mm_json_client/generic_type.rb', line 25 def set_properties @data.keys.sort.map(&:to_s) end |
#to_h ⇒ Object
29 30 31 |
# File 'lib/mm_json_client/generic_type.rb', line 29 def to_h {}.merge(@data) end |