Class: ActiveResource::Reflection::AssociationReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_resource/reflection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(macro, name, options) ⇒ AssociationReflection


29
30
31
# File 'lib/active_resource/reflection.rb', line 29

def initialize(macro, name, options)
  @macro, @name, @options = macro, name, options
end

Instance Attribute Details

#macroObject (readonly)

Returns the macro type.

has_many :clients returns :has_many


41
42
43
# File 'lib/active_resource/reflection.rb', line 41

def macro
  @macro
end

#nameObject (readonly)

Returns the name of the macro.

has_many :clients returns :clients


36
37
38
# File 'lib/active_resource/reflection.rb', line 36

def name
  @name
end

#optionsObject (readonly)

Returns the hash of options used for the macro.

has_many :clients returns {}


46
47
48
# File 'lib/active_resource/reflection.rb', line 46

def options
  @options
end

Instance Method Details

#class_nameObject

Returns the class name for the macro.

has_many :clients returns 'Client'


58
59
60
# File 'lib/active_resource/reflection.rb', line 58

def class_name
  @class_name ||= derive_class_name
end

#foreign_keyObject

Returns the foreign_key for the macro.


63
64
65
# File 'lib/active_resource/reflection.rb', line 63

def foreign_key
  @foreign_key ||= self.options[:foreign_key] || "#{self.name.to_s.downcase}_id"
end

#klassObject

Returns the class for the macro.

has_many :clients returns the Client class


51
52
53
# File 'lib/active_resource/reflection.rb', line 51

def klass
  @klass ||= class_name.constantize
end