class SmoothOperator::Associations::AssociationReflection

Attributes

macro[R]

Public Class Methods

new(association, related_reflection, options) click to toggle source
Calls superclass method
# File lib/smooth_operator/associations/association_reflection.rb, line 9
def initialize(association, related_reflection, options)
  super(association, options)

  @related_reflection, @macro = related_reflection, options[:macro]
end

Public Instance Methods

belongs_to?() click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 55
def belongs_to?
  macro == :belongs_to
end
collection?() click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 59
def collection?
  has_many?
end
foreign_key() click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 19
def foreign_key
  @foreign_key ||= options[:foreign_key] || foreign_key_default
end
has_many?() click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 47
def has_many?
  macro == :has_many
end
has_one?() click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 51
def has_one?
  macro == :has_one
end
primary_key() click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 15
def primary_key
  @primary_key ||= options[:primary_key] || :id
end
primary_key_of(object) click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 43
def primary_key_of(object)
  object.send(primary_key)
end
rails_serialization?() click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 63
def rails_serialization?
  options[:rails_serialization] == true
end
set_foreign_key(object, id) click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 33
def set_foreign_key(object, id)
  setter = "#{foreign_key}="

  if object.respond_to?(setter)
    object.send(setter, id)
  elsif object.respond_to?("send_to_representative")
    object.send_to_representative(setter, id)
  end
end
set_relational_keys(origin, destination) click to toggle source
# File lib/smooth_operator/associations/association_reflection.rb, line 23
def set_relational_keys(origin, destination)
  return nil if options[:standalone] == true

  if has_many? || has_one?
    set_foreign_key(destination, primary_key_of(origin))
  elsif belongs_to?
    set_foreign_key(origin, primary_key_of(destination))
  end
end