Module: Latitude::API::Attributes::ClassMethods

Included in:
Latitude::API::APIObject, Latitude::API::APIResource
Defined in:
lib/latitude/api/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, type = :string, **opts) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/latitude/api/attributes.rb', line 16

def attribute(name, type = :string, **opts)
  name = name.to_s
  read_only = opts.fetch(:read_only, false)
  attribute_specs[name] = Spec.new(name: name, type: type, read_only: read_only)

  unless RESERVED_NAMES.include?(name)
    define_method(name) { read_attribute(name) }
    define_method("#{name}=") { |value| write_attribute(name, value) } unless read_only
  end

  attribute_specs[name]
end

#attribute_specsObject



29
30
31
# File 'lib/latitude/api/attributes.rb', line 29

def attribute_specs
  @attribute_specs ||= (superclass.respond_to?(:attribute_specs) ? superclass.attribute_specs : {}).dup
end