Class: Mobility::Backends::ActiveRecord::KeyValue::Visitor

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

Overview

Internal class used to visit all nodes in a predicate clause and return a hash of key/value pairs corresponding to attributes (keys) and the respective join type (values) required for each attribute.

Example:

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

backend_class = Post.mobility_backend_class(:title)
visitor = Mobility::Backends::ActiveRecord::KeyValue::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("foo").and(content.eq(nil)))
#=> { title: Arel::Nodes::InnerJoin, content: Arel::Nodes::OuterJoin }

The title predicate has a non-nil value, so we can use an INNER JOIN, whereas we are searching for nil content, which requires an OUTER 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