Class: MultiTenant::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-multi-tenant/query_rewriter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arel_node) ⇒ Context

Returns a new instance of Context.


31
32
33
34
35
36
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 31

def initialize(arel_node)
  @arel_node = arel_node
  @known_relations = []
  @handled_relations = []
  @discovering = false
end

Instance Attribute Details

#arel_nodeObject (readonly)

Returns the value of attribute arel_node.


29
30
31
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 29

def arel_node
  @arel_node
end

#handled_relationsObject (readonly)

Returns the value of attribute handled_relations.


29
30
31
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 29

def handled_relations
  @handled_relations
end

#known_relationsObject (readonly)

Returns the value of attribute known_relations.


29
30
31
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 29

def known_relations
  @known_relations
end

Instance Method Details

#discover_relationsObject


38
39
40
41
42
43
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 38

def discover_relations
  old_discovering = @discovering
  @discovering = true
  yield
  @discovering = old_discovering
end

#unhandled_relationsObject


54
55
56
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 54

def unhandled_relations
  known_relations.uniq - handled_relations
end

#visited_handled_relation(relation) ⇒ Object


50
51
52
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 50

def visited_handled_relation(relation)
  @handled_relations << Table.new(relation)
end

#visited_relation(relation) ⇒ Object


45
46
47
48
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 45

def visited_relation(relation)
  return unless @discovering
  @known_relations << Table.new(relation)
end