lib/mongoid/report.rb in mongoid-report-0.1.3 vs lib/mongoid/report.rb in mongoid-report-0.1.5

- old
+ new

@@ -1,8 +1,9 @@ require 'active_support/concern' require 'active_support/core_ext/class/attribute' +require_relative 'report/config' require_relative 'report/queries_builder' require_relative 'report/attach_proxy' require_relative 'report/collection' require_relative 'report/scope' require_relative 'report/scope_collection' @@ -17,12 +18,24 @@ class_attribute :settings self.settings = {} + def self.inherited(subclass) + subclass.settings = self.settings.dup + end + + # Variable for copying internal class settings to the instance because of + # possible modifications in case of using filters with lambda + # expressions. + attr_reader :report_module_settings + def initialize_report_module - self.class.settings.each do |klass, configuration| + # Lets store settings under created instance. + @report_module_settings = self.class.settings.dup + + @report_module_settings.each do |klass, configuration| builder = QueriesBuilder.new(configuration) # Prepare group queries depends on the configuration in the included # class. @queries = builder.do @@ -33,11 +46,11 @@ end end alias :initialize :initialize_report_module def queries(klass) - self.class.settings[klass][:queries] + report_module_settings[klass][:queries] end # We should pass here mongoid document def aggregate_for(report_name) Scope.new(self, report_name) @@ -138,9 +151,10 @@ { for: collection, fields: ActiveSupport::OrderedHash.new, group_by: [], queries: [], + compiled: false, columns: ActiveSupport::OrderedHash.new, } end end