forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate arel generation from field/tag parsing
When `Field` was extracted it was attractive to let it be a middleman between `MiqExpression` and the Arel library since everything goes through `Field#arel_attribute`. While this started out as straightforward delegation, more supporting code was required to bridge more complex expressions such as `CONTAINS`, or things that require extra arguments like `matches`, etc.. I think that consequently `Field` (and `Tag`) have taken too much on in terms of responsibility. It also introduced a cohesion problem in that not all fields are concerned with columns in the database. While this change might be a step back for `MiqExpression`, I think it greatly improves `Field`. I think there are better patterns out there for better separating responsibilities here, but that can be left to a future revision.
- Loading branch information
1 parent
7fbf5ba
commit eb9ed5b
Showing
4 changed files
with
82 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class MiqExpression | ||
class WhereExtractionVisitor < Arel::Visitors::PostgreSQL | ||
def visit_Arel_Nodes_SelectStatement(o, collector) | ||
collector = o.cores.inject(collector) do |c, x| | ||
visit_Arel_Nodes_SelectCore(x, c) | ||
end | ||
end | ||
|
||
def visit_Arel_Nodes_SelectCore(o, collector) | ||
unless o.wheres.empty? | ||
len = o.wheres.length - 1 | ||
o.wheres.each_with_index do |x, i| | ||
collector = visit(x, collector) | ||
collector << AND unless len == i | ||
end | ||
end | ||
|
||
collector | ||
end | ||
end | ||
end |