From 9018c506736711ac2e1fa82577d3a3344a2e789d Mon Sep 17 00:00:00 2001 From: rkh Date: Thu, 27 May 2010 08:47:25 +0000 Subject: [PATCH] recent changes git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1131 7926756e-e54e-46e6-9721-ed318f58905e --- app/models/cost_query/walker.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/cost_query/walker.rb b/app/models/cost_query/walker.rb index 1f8f522231..263f2217b3 100644 --- a/app/models/cost_query/walker.rb +++ b/app/models/cost_query/walker.rb @@ -4,8 +4,8 @@ class CostQuery::Walker def initialize(query) @query = query - end + end ## # @return [CostQuery::Result::Base] Result tree with row group bys at the top # @see CostQuery::Chainable#result @@ -44,7 +44,21 @@ class CostQuery::Walker columns + rows end - def walk - raise NotImplementedError, "done" + ## + # @example + # query.walk(:column_first) do |current, subgregation| + # if subgregation.nil? + # ["#{current.count}"] + # elsif current.type == :column + # subgregation.first.unshift "#{current.group_fields}" + # else + # subgregation.flatten + # end + # end + def walk(result = nil, &block) + result ||= row_first + result = send result if result.is_a? Symbol + return block.call(result, nil) unless result.has_children? + block.call result, result.map { |r| walk(r, &block) } end end