Improving Report#hash to be semantically more useful

pull/6827/head
Gregor Schmidt 14 years ago
parent dee81d52cb
commit 8b4ddbb230
  1. 25
      lib/report.rb

@ -135,13 +135,23 @@ class Report < ActiveRecord::Base
end end
def hash def hash
filter_string = filters.inject("") do |str, f| report_string = ""
str + f.class.underscore_name + f.operator.to_s + (f.values ? f.values.to_json : "")
end report_string.concat('filters: [')
filter_string = group_bys.collect(&:class).sort_by(&:underscore_name).inject(filter_string) do |string, gb| report_string.concat(filters.map { |f|
string.concat(gb.underscore_name) f.class.underscore_name + f.operator.to_s + (f.values ? f.values.to_json : "")
end }.sort.join(', '))
filter_string.hash report_string.concat(']')
report_string.concat(', group_bys: {')
report_string.concat(group_bys.group_by(&:type).map { |t, gbs|
"#{t} : [#{gbs.collect(&:class).collect(&:underscore_name).join(', ')}]"
}.join(', '))
report_string.concat('}')
report_string.hash
end end
def == another_report def == another_report
@ -153,5 +163,4 @@ class Report < ActiveRecord::Base
def minimal_chain! def minimal_chain!
@chain = self.class::Filter::NoFilter.new @chain = self.class::Filter::NoFilter.new
end end
end end

Loading…
Cancel
Save