class Sequel::Plugins::AssociationProxies::AssociationProxy

A proxy for the association. Calling an array method will load the associated objects and call the method on the associated object array. Calling any other method will call that method on the association's dataset.

Constants

DEFAULT_PROXY_TO_DATASET

Default proc used to determine whether to send the method to the dataset. If the array would respond to it, sends it to the array instead of the dataset.

Public Class Methods

new(instance, reflection, proxy_argument, &proxy_block) click to toggle source

Set the association reflection to use, and whether the association should be reloaded if an array method is called.

   # File lib/sequel/plugins/association_proxies.rb
84 def initialize(instance, reflection, proxy_argument, &proxy_block)
85   @instance = instance
86   @reflection = reflection
87   @proxy_argument = proxy_argument
88   @proxy_block = proxy_block
89 end

Public Instance Methods

method_missing(meth, *args, &block) click to toggle source

Call the method given on the array of associated objects if the method is an array method, otherwise call the method on the association's dataset.

    # File lib/sequel/plugins/association_proxies.rb
 93 def method_missing(meth, *args, &block)
 94   v = if @instance.model.association_proxy_to_dataset.call(:method=>meth, :arguments=>args, :block=>block, :instance=>@instance, :reflection=>@reflection, :proxy_argument=>@proxy_argument, :proxy_block=>@proxy_block)
 95     @instance.public_send(@reflection[:dataset_method])
 96   else
 97     @instance.send(:load_associated_objects, @reflection, @proxy_argument, &@proxy_block)
 98   end
 99   v.public_send(meth, *args, &block)
100 end