class ALD::API::CollectionEntry
Base class for entries in a collection returned by the ALD API. This class is used internally and should not be called by library consumers.
Child classes inheriting from this class must support:
@data - a Hash containing the entry's data @initialized - a Boolean indicating whether @data is yet complete or not #request - load missing information into @data
Public
↑ topPublic Instance Methods
Internal
↑ topPublic Class Methods
Dynamically define attributes determined by child classes. This is called by ::new to define the attributes child classes define in ::initialized_attributes and ::requested_attributes.
Returns¶ ↑
Returns nothing.
# File lib/ALD/collection_entry.rb, line 57 def self.define_attributes! return if @attributes_defined initialized_attributes.each do |attr| self.send(:define_method, attr.to_sym) do @data[attr] end end requested_attributes.each do |attr| self.send(:define_method, attr.to_sym) do request unless initialized? @data[attr] end end @attributes_defined = true end
Create a new entry with the given data
- api
-
the ALD:API instance this entry belongs to
- data
-
the initial, possibly uncomplete @data hash
- initialized
-
a Boolean indicating whether data is already complete or not
# File lib/ALD/collection_entry.rb, line 20 def initialize(api, data, initialized = false) @api, @data, @initialized = api, data, initialized self.class.define_attributes! end
Child classes override this to specify attributes that are not always present in @data. For each such attribute, a retrieval method including a call to #request is dynamically defined.
Returns¶ ↑
Returns an Array of attribute names (String)
# File lib/ALD/collection_entry.rb, line 48 def self.requested_attributes [] end