Module: RemoteResource::Attributes

Includes:
Notifications
Included in:
Base
Defined in:
lib/remote_resource/base/attributes.rb

Overview

Defines attribute related methods for Base class instances.

Instance Method Summary collapse

Methods included from Notifications

#instrument, #instrument_attribute

Instance Method Details

#create_attributes(base_instance) ⇒ Object

Public: Creates and returns an array of cached attributes for the provided base_instance. The base_instance is stored in each attribute and is used for lookup.

base_instance - an instance of base_class. The instance means that the scope has already been applied to it.

Returns an array a AttributeSpecifications.



14
15
16
17
18
# File 'lib/remote_resource/base/attributes.rb', line 14

def create_attributes(base_instance)
  @attributes = base_instance.class.attributes.map do |method, _value|
    AttributeSpecification.new(method, base_instance)
  end
end

#get_attribute(name) ⇒ Object

Public: Returns the value of the provided attribute. It uses the application configured lookup_method to do so.

name - a Symbol representing an attribute name

Returns the value of the attribute as a String.



26
27
28
29
30
31
32
33
34
# File 'lib/remote_resource/base/attributes.rb', line 26

def get_attribute(name)
  attribute = find_attribute(name)

  attr_lookup = RemoteResource.lookup_method
  lookup_name = attr_lookup.class.name
  instrument_attribute('find', attribute, lookup_method: lookup_name) do
    attr_lookup.find(attribute).value
  end
end