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



19
20
21
22
23
24
25
# File 'lib/octopus/relation_proxy.rb', line 19

def method_missing(method, *args, &block)
  if block
    @ar_relation.public_send(method, *args, &block)
  else
    run_on_shard { @ar_relation.public_send(method, *args) }
  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?



27
28
29
30
31
32
33
34
# File 'lib/octopus/relation_proxy.rb', line 27

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