lib/mongoid/report/queries_builder.rb in mongoid-report-0.0.6 vs lib/mongoid/report/queries_builder.rb in mongoid-report-0.0.7

- old
+ new

@@ -2,13 +2,13 @@ module Report QueriesBuilder = Struct.new(:settings) do def do [].tap do |queries| - queries.concat([{ '$project' => query1 }]) - queries.concat([{ '$group' => query2 }]) - queries.concat([{ '$project' => query3 }]) + queries.concat([{ '$project' => project_query }]) + queries.concat([{ '$group' => group_query }]) + queries.concat([{ '$project' => project_group_fields_query }]) end end private @@ -31,18 +31,18 @@ .concat(fields) .concat(groups) end # Example: { '$project' => { :field1 => 1 } } - def query1 + def project_query all_fields.inject({}) do |hash, field| hash.merge!(field => 1) end end GROUP_TEMPLATE = "$%s" - def query2 + def group_query {}.tap do |query| query[:_id] = {} groups.inject(query[:_id]) do |hash, group| hash.merge!(group => GROUP_TEMPLATE % group) @@ -53,10 +53,10 @@ end end end PROJECT_TEMPLATE = "$_id.%s" - def query3 + def project_group_fields_query {}.tap do |query| if groups == [:_id] query[:_id] = '$_id' else query[:_id] = 0