class Her::Model::Associations::AssociationProxy

Public Instance Methods

loaded?() click to toggle source

Returns true if the association has been loaded, otherwise false.

# File lib/her_extension/model/associations/association_proxy.rb, line 11
def loaded?
  !!association.instance_variable_get('@cached_result')
end
method_missing(name, *args, &block) click to toggle source
# File lib/her_extension/model/associations/association_proxy.rb, line 15
def method_missing(name, *args, &block)
  if :object_id == name # avoid redefining object_id
    return association.fetch.object_id
  end

  # Check if a class scope has previously been defined
  begin
    if Relation.scopes.keys.grep(::Regexp.new(name.to_s)).any?
      return self.association.send(name,*args,&block)
    end
  rescue ::NoMethodError => e
  end

  # create a proxy to the fetched object's method
  # https://github.com/remiprev/her/pull/377
  AssociationProxy.install_proxy_methods 'association.fetch', name

  # resend message to fetched object
  __send__(name, *args, &block)
end