module ContextIO::API::ResourceCollection::DeclarativeClassSyntax
This module contains helper methods for ‘API::ResourceCollection`s’ class definitions. It gets ‘extend`ed into a class when `API::ResourceCollection` is `include`d.
Public Instance Methods
@!attribute [r] association_name
@return [Symbol] The association name registered for this resource.
# File lib/contextio/api/resource_collection.rb, line 149 def association_name @association_name end
@!attribute [r] associations
@return [Array<String] An array of the belong_to associations for the collection
# File lib/contextio/api/resource_collection.rb, line 143 def associations @associations ||= [] end
Private Instance Methods
Declares the association name for the resource.
@param [String, Symbol] association_name
The name.
# File lib/contextio/api/resource_collection.rb, line 186 def association_name=(association_name) @association_name = association_name.to_sym ContextIO::API::AssociationHelpers.register_resource(self, @association_name) end
Declares which class, if any, the collection belongs to. It defines an accessor for the belonged-to object.
@param [Symbol] association_name
The name of the association for the
class in question. Singular classes will have singular names registered. For instance, :message should reger to the Message resource.
# File lib/contextio/api/resource_collection.rb, line 175 def belongs_to(association_name) define_method(association_name) do instance_variable_get("@#{association_name}") end associations << association_name end
Declares which class the ‘ResourceCollection` is intended to wrap. For best results, this should probably be a `Resource`. It defines an accessor for this class on instances of the collection, which is private. Make sure your collection class has required the file with the defeniiton of the class it wraps.
@param [Class] klass The class that the collection, well, collects.
# File lib/contextio/api/resource_collection.rb, line 162 def resource_class=(klass) define_method(:resource_class) do klass end end