-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial commit * fix spacing * add a couple tests * add two more tests * fix nested belongs_to select statements * changelog and readme * remove unused delegator * add hole in spec to cover regression * remove forwardable as per code review
- Loading branch information
Showing
8 changed files
with
134 additions
and
24 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
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,41 @@ | ||
module ActiveForce | ||
class SelectBuilder | ||
|
||
attr_reader :selected_fields, :nested_query_fields, :non_nested_query_fields, :query | ||
|
||
def initialize(selected_fields, query) | ||
@query = query | ||
@selected_fields = selected_fields | ||
@non_nested_query_fields = [] | ||
@nested_query_fields = [] | ||
end | ||
|
||
def parse | ||
selected_fields.each do |field| | ||
case field | ||
when Symbol | ||
non_nested_query_fields << query.mappings[field] | ||
when Hash | ||
populate_nested_query_fields(field) | ||
when String | ||
non_nested_query_fields << field | ||
end | ||
end | ||
{non_nested_query_fields: non_nested_query_fields, nested_query_fields: nested_query_fields} | ||
end | ||
|
||
private | ||
|
||
def populate_nested_query_fields(field) | ||
field.each do |key, value| | ||
case value | ||
when Symbol | ||
field[key] = [value] | ||
when Hash | ||
raise ArgumentError, 'Nested Hash is not supported in select statement, you may wish to use an Array' | ||
end | ||
end | ||
nested_query_fields << field | ||
end | ||
end | ||
end |
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