Class: Immunio::ArelNodeVisitor
- Inherits:
-
Arel::Visitors::Visitor
- Object
- Arel::Visitors::Visitor
- Immunio::ArelNodeVisitor
- Defined in:
- lib/immunio/plugins/active_record.rb
Overview
Arel AST visitor to collect params and modifiers. Based on Arel::Visitors::DepthFirst.
Whenever a query is built in Rails, a tree of Ruby objects (AST) is built to represent that query. Arel (the engine building this tree) uses a Visitor to build the SQL statement represented by tree. We use the same base class as Arel, but instead of building some SQL, we track the params and modifiers.
Constant Summary collapse
- VISITABLES =
Only accepts statements to avoid duplicates in params if branches are visited multiple times.
[Arel::Nodes::SelectStatement, Arel::Nodes::InsertStatement, Arel::Nodes::UpdateStatement, Arel::Nodes::DeleteStatement].freeze
- IGNORED_EXPRESSIONS =
["", "*", "1 AS one"].freeze
- DISPATCH =
Copied from Arel::Visitors::Visitor to ensure the cached dispatch table isn’t shared with other Arel visitors under Rails 3.2.
Hash.new do |hash, klass| hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}" end
Instance Method Summary collapse
-
#accept(object) ⇒ Object
Entry point into the visitor.
- #dispatch ⇒ Object
-
#initialize(connection_id) ⇒ ArelNodeVisitor
constructor
A new instance of ArelNodeVisitor.
Constructor Details
#initialize(connection_id) ⇒ ArelNodeVisitor
Returns a new instance of ArelNodeVisitor.
130 131 132 133 |
# File 'lib/immunio/plugins/active_record.rb', line 130 def initialize(connection_id) @connection_id = connection_id super() end |
Instance Method Details
#accept(object) ⇒ Object
Entry point into the visitor.
136 137 138 139 140 |
# File 'lib/immunio/plugins/active_record.rb', line 136 def accept(object) if VISITABLES.include?(object.class) visit object, {} end end |
#dispatch ⇒ Object
142 143 144 |
# File 'lib/immunio/plugins/active_record.rb', line 142 def dispatch DISPATCH end |