Sha256: 0d98e9f8da7134b88a365649c0b59eea3d04c3c3fac3138ac5d6b8620cb5dd48

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

module Octopus
  class RelationProxy
    include Octopus::ShardTracking::Attribute

    attr_accessor :ar_relation

    def initialize(shard, ar_relation)
      @current_shard = shard
      @ar_relation = ar_relation
    end

    def method_missing(method, *args, &block)
      run_on_shard { @ar_relation.send(method, *args, &block) }
    end

    def respond_to?(*args)
      super || @ar_relation.respond_to?(*args)
    end

    # these methods are not normally sent to method_missing

    def select(*args, &block)
      method_missing(:select, *args, &block)
    end

    def inspect
      method_missing(:inspect)
    end

    def as_json(options = nil)
      method_missing(:as_json, options)
    end

    def ==(other)
      case other
      when Octopus::RelationProxy
        method_missing(:==, other.ar_relation)
      else
        method_missing(:==, other)
      end
    end
    alias_method :eql?, :==
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar-octopus-0.8.3 lib/octopus/relation_proxy.rb