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.



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

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.



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

def arel_node
  @arel_node
end

#handled_relationsObject (readonly)

Returns the value of attribute handled_relations.



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

def handled_relations
  @handled_relations
end

#known_relationsObject (readonly)

Returns the value of attribute known_relations.



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

def known_relations
  @known_relations
end

Instance Method Details

#discover_relationsObject



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

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

#unhandled_relationsObject



56
57
58
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 56

def unhandled_relations
  known_relations.uniq - handled_relations
end

#visited_handled_relation(relation) ⇒ Object



52
53
54
# File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 52

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

#visited_relation(relation) ⇒ Object



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

def visited_relation(relation)
  return unless @discovering

  @known_relations << Table.new(relation)
end