Class: RemoteResource::AttributeSpecification
- Inherits:
-
Object
- Object
- RemoteResource::AttributeSpecification
- Defined in:
- lib/remote_resource/attribute_specification.rb
Overview
A value object representing an attribute defined in RemoteResource::Base. An AttributeSpecification contains the attributes’ method name, its resource, and its API client that is used for lookup. It also calculates its key which is used to lookup its value in storage.
scope is evaluated outside of this object and should remain unchanged throughout its life cycle. scope is used in building the attribute’s key and its equality. target_object on the other hand is just a reference to the object that scope was evaluated on. It may change throughout the attribute’s life cycle and is not used in determining equality.
Instance Attribute Summary collapse
-
#base_class ⇒ Object
readonly
Returns the value of attribute base_class.
-
#name ⇒ Object
(also: #method)
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, base_class) ⇒ AttributeSpecification
constructor
A new instance of AttributeSpecification.
- #key ⇒ Object
- #location ⇒ Object
- #resource(resource_client = nil) ⇒ Object
- #resource_name ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, base_class) ⇒ AttributeSpecification
Returns a new instance of AttributeSpecification.
19 20 21 22 |
# File 'lib/remote_resource/attribute_specification.rb', line 19 def initialize(name, base_class) @name = name @base_class = base_class end |
Instance Attribute Details
#base_class ⇒ Object (readonly)
Returns the value of attribute base_class.
16 17 18 |
# File 'lib/remote_resource/attribute_specification.rb', line 16 def base_class @base_class end |
#name ⇒ Object (readonly) Also known as: method
Returns the value of attribute name.
16 17 18 |
# File 'lib/remote_resource/attribute_specification.rb', line 16 def name @name end |
Instance Method Details
#key ⇒ Object
46 47 48 49 |
# File 'lib/remote_resource/attribute_specification.rb', line 46 def key @key ||= AttributeKey.new(@base_class.class.underscore, resource_name, @base_class.scope, @name) end |
#location ⇒ Object
42 43 44 |
# File 'lib/remote_resource/attribute_specification.rb', line 42 def location "#{@base_class.class.name}##{@name}" end |
#resource(resource_client = nil) ⇒ Object
38 39 40 |
# File 'lib/remote_resource/attribute_specification.rb', line 38 def resource(resource_client = nil) @base_class.send(:resource, resource_name, resource_client) end |
#resource_name ⇒ Object
34 35 36 |
# File 'lib/remote_resource/attribute_specification.rb', line 34 def resource_name @base_class.class.attributes[@name] end |
#to_hash ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/remote_resource/attribute_specification.rb', line 25 def to_hash { name: @name, resource: resource_name, base_class: @base_class.class.symbol_name, location: location } end |