Class Sequel::Plugins::AssociationProxies::AssociationProxy
In: lib/sequel/plugins/association_proxies.rb
Parent: BasicObject

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.

Methods

Constants

DEFAULT_PROXY_TO_DATASET = proc{|opts| !array.respond_to?(opts[:method])}   Default proc used to determine whether to sent the method to the dataset. If the array would respond to it, sends it to the array instead of the dataset.

Public Class methods

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

[Source]

    # File lib/sequel/plugins/association_proxies.rb, line 72
72:         def initialize(instance, reflection, proxy_argument, &proxy_block)
73:           @instance = instance
74:           @reflection = reflection
75:           @proxy_argument = proxy_argument
76:           @proxy_block = proxy_block
77:         end

Public Instance methods

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.

[Source]

    # File lib/sequel/plugins/association_proxies.rb, line 81
81:         def method_missing(meth, *args, &block)
82:           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)
83:             @instance.public_send(@reflection[:dataset_method])
84:           else
85:             @instance.send(:load_associated_objects, @reflection, @proxy_argument, &@proxy_block)
86:           end
87:           v.public_send(meth, *args, &block)
88:         end

[Validate]