Module: Latitude::API::Attributes::InstanceMethods
- Included in:
- Latitude::API::APIObject, Latitude::API::APIResource
- Defined in:
- lib/latitude/api/attributes.rb
Instance Method Summary collapse
Instance Method Details
#attribute_spec(name) ⇒ Object
35 36 37 |
# File 'lib/latitude/api/attributes.rb', line 35 def attribute_spec(name) self.class.respond_to?(:attribute_specs) ? self.class.attribute_specs[name.to_s] : nil end |
#read_attribute(name) ⇒ Object
39 40 41 |
# File 'lib/latitude/api/attributes.rb', line 39 def read_attribute(name) @values[name.to_s] end |
#wrap_attribute(key, value) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/latitude/api/attributes.rb', line 43 def wrap_attribute(key, value) type = attribute_spec(key)&.type if type.is_a?(Array) klass = type.first return Array(value).map { |v| v.is_a?(Hash) ? klass.new(v) : v } if object_class?(klass) elsif object_class?(type) return value.is_a?(Hash) ? type.new(value) : value end APIObject.wrap(value) end |