Class: Octopus::RelationProxy

Inherits:
BasicObject
Includes:
ShardTracking::Attribute
Defined in:
lib/octopus/relation_proxy.rb

Defined Under Namespace

Modules: CaseFixer

Instance Attribute Summary collapse

Attributes included from ShardTracking::Attribute

#current_shard

Instance Method Summary collapse

Methods included from ShardTracking::Attribute

included, #set_current_shard

Constructor Details

#initialize(shard, ar_relation) ⇒ RelationProxy

Returns a new instance of RelationProxy.



14
15
16
17
# File 'lib/octopus/relation_proxy.rb', line 14

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/octopus/relation_proxy.rb', line 23

def method_missing(method, *args, &block)
  if block
    @ar_relation.public_send(method, *args, &block)
  else
    run_on_shard do
      if method == :load_records
        @ar_relation.send(method, *args)
      else
        @ar_relation.public_send(method, *args)
      end
    end
  end
end

Instance Attribute Details

#ar_relationObject

Returns the value of attribute ar_relation.



12
13
14
# File 'lib/octopus/relation_proxy.rb', line 12

def ar_relation
  @ar_relation
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



37
38
39
40
41
42
43
44
# File 'lib/octopus/relation_proxy.rb', line 37

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

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/octopus/relation_proxy.rb', line 19

def respond_to?(*args)
  method_missing(:respond_to?, *args)
end