lib/mongoid/report.rb in mongoid-report-0.1.1 vs lib/mongoid/report.rb in mongoid-report-0.1.2

- old
+ new

@@ -85,10 +85,20 @@ add_field(report_name, column, name) end end end + def column(*fields) + # Because of representing fields as hash instead of columns we should + # have the last variable as columns. + define_report_method(*fields) do |_, report_name, columns| + columns.each do |name, function| + add_column(report_name, name, function) + end + end + end + def fields(collection) settings_property(collection, :fields, {}) end def groups(collection) @@ -125,18 +135,23 @@ def initialize_settings_by(attach_name, collection) settings[attach_name] ||= settings.fetch(attach_name) do { for: collection, - fields: {}, + fields: ActiveSupport::OrderedHash.new, group_by: [], queries: [], + columns: ActiveSupport::OrderedHash.new, } end end def add_field(attach_name, field, name) settings[attach_name][:fields][field] = name + end + + def add_column(attach_name, name, function) + settings[attach_name][:columns][name] = function end end end