Class: Mobility::Backends::ActiveRecord::Table::Visitor

Inherits:
Plugins::Arel::Visitor show all
Defined in:
lib/mobility/backends/active_record/table.rb

Overview

Internal class used to visit all nodes in a predicate clause and return a single join type required for the predicate, or nil if no join is required. (Similar to the KeyValue Visitor class.)

Example:

class Post < ApplicationRecord
  extend Mobility
  translates :title, :content, backend: :table
end

backend_class = Post.mobility_backend_class(:title)
visitor = Mobility::Backends::ActiveRecord::Table::Visitor.new(backend_class, :en)

title   = backend_class.build_node("title", :en)   # arel node for title
content = backend_class.build_node("content", :en) # arel node for content

visitor.accept(title.eq(nil).and(content.eq(nil)))
#=> Arel::Nodes::OuterJoin

visitor.accept(title.eq("foo").and(content.eq(nil)))
#=> Arel::Nodes::InnerJoin

In the first case, both attributes are matched against nil values, so we need an OUTER JOIN. In the second case, one attribute is matched against a non-nil value, so we can use an INNER JOIN.

Constant Summary

Constants inherited from Plugins::Arel::Visitor

Plugins::Arel::Visitor::INNER_JOIN, Plugins::Arel::Visitor::OUTER_JOIN

Instance Attribute Summary

Attributes inherited from Plugins::Arel::Visitor

#backend_class, #locale

Method Summary

Methods inherited from Plugins::Arel::Visitor

#initialize

Constructor Details

This class inherits a constructor from Mobility::Plugins::Arel::Visitor