class ActiveResource::Reflection::AssociationReflection

Attributes

macro[R]

Returns the macro type.

has_many :clients returns :has_many

name[R]

Returns the name of the macro.

has_many :clients returns :clients

options[R]

Returns the hash of options used for the macro.

has_many :clients returns +{}+

Public Class Methods

new(macro, name, options) click to toggle source
# File lib/active_resource/reflection.rb, line 29
def initialize(macro, name, options)
  @macro, @name, @options = macro, name, options
end

Public Instance Methods

class_name() click to toggle source

Returns the class name for the macro.

has_many :clients returns 'Client'

# File lib/active_resource/reflection.rb, line 58
def class_name
  @class_name ||= derive_class_name
end
foreign_key() click to toggle source

Returns the foreign_key for the macro.

# File lib/active_resource/reflection.rb, line 63
def foreign_key
  @foreign_key ||= self.options[:foreign_key] || "#{self.name.to_s.downcase}_id"
end
klass() click to toggle source

Returns the class for the macro.

has_many :clients returns the Client class

# File lib/active_resource/reflection.rb, line 51
def klass
  @klass ||= class_name.constantize
end

Private Instance Methods

derive_class_name() click to toggle source
# File lib/active_resource/reflection.rb, line 68
def derive_class_name
  return (options[:class_name] ? options[:class_name].to_s.camelize : name.to_s.classify)
end
derive_foreign_key() click to toggle source
# File lib/active_resource/reflection.rb, line 72
def derive_foreign_key
  return options[:foreign_key] ? options[:foreign_key].to_s : "#{name.to_s.downcase}_id"
end