class MultiTenant::ArelTenantVisitor
Constants
- DISPATCH
Attributes
contexts[R]
Public Class Methods
new(arel)
click to toggle source
Calls superclass method
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 60 def initialize(arel) super(Proc.new {}) @statement_node_id = nil @contexts = [] @current_context = nil accept(arel.ast) end
Public Instance Methods
visit_Arel_Attributes_Attribute(*args)
click to toggle source
Calls superclass method
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 71 def visit_Arel_Attributes_Attribute(*args) return if @current_context.nil? super(*args) end
visit_Arel_Nodes_Equality(o, *args)
click to toggle source
Calls superclass method
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 76 def visit_Arel_Nodes_Equality(o, *args) if o.left.is_a?(Arel::Attributes::Attribute) table_name = o.left.relation.table_name model = MultiTenant.multi_tenant_model_for_table(table_name) @current_context.visited_handled_relation(o.left.relation) if model.present? && o.left.name.to_s == model.partition_key.to_s end super(o, *args) end
visit_Arel_Nodes_OuterJoin(o, collector = nil)
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 114 def visit_Arel_Nodes_OuterJoin(o, collector = nil) nest_context(o) do @current_context.discover_relations do visit o.left visit o.right end end end
Also aliased as: visit_Arel_Nodes_FullOuterJoin, visit_Arel_Nodes_RightOuterJoin
visit_Arel_Nodes_SelectCore(o, *args)
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 98 def visit_Arel_Nodes_SelectCore(o, *args) nest_context(o) do @current_context.discover_relations do visit o.source end visit o.wheres visit o.groups visit o.windows if defined?(o.having) visit o.having else visit o.havings end end end
visit_Arel_Table(o, _collector = nil)
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 93 def visit_Arel_Table(o, _collector = nil) @current_context.visited_relation(o) if tenant_relation?(o.table_name) end
Also aliased as: visit_Arel_Nodes_TableAlias
visit_MultiTenant_TenantEnforcementClause(o, *)
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 85 def visit_MultiTenant_TenantEnforcementClause(o, *) @current_context.visited_handled_relation(o.tenant_attribute.relation) end
visit_MultiTenant_TenantJoinEnforcementClause(o, *)
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 89 def visit_MultiTenant_TenantJoinEnforcementClause(o, *) @current_context.visited_handled_relation(o.tenant_attribute.relation) end
Private Instance Methods
dispatch()
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 135 def dispatch DISPATCH end
get_dispatch_cache()
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 139 def get_dispatch_cache dispatch end
nest_context(o) { || ... }
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 143 def nest_context(o) old_context = @current_context @current_context = Context.new(o) @contexts << @current_context yield @current_context = old_context end
tenant_relation?(table_name)
click to toggle source
# File lib/activerecord-multi-tenant/query_rewriter.rb, line 127 def tenant_relation?(table_name) MultiTenant.multi_tenant_model_for_table(table_name).present? end