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

association_name() click to toggle source

@!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
associations() click to toggle source

@!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

association_name=(association_name) click to toggle source

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
belongs_to(association_name) click to toggle source

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
resource_class=(klass) click to toggle source

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