Sha256: 3d69b55f27754b625cdcf1a72b5565331e7cdd73ff23c1ea49eebc08108cc1f2

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

module Lopata
  GroupTree = Struct.new(:group, :items, :title) do
    def status
      # return @status if @status
      statuses = items.map(&:status).uniq
      @status = 
        if statuses.length == 1
          statuses.first
        elsif statuses.include?(:failed)
          :failed
        elsif 
          statuses.first
        end
      @status
    end

    # Returns steps hierarhy: Group with nestet setps or groups
    def self.steps_hierarhy(steps)
      top = GroupTree.new(nil, [], '')
      hierarhy = [top]
      current_groups = []
      steps.each do |step|
        if step.groups == current_groups
          hierarhy.last.items << step
        else
          # ensure hierarhy to is in current step tree - remove from hierary all groups not in new tree.
          while hierarhy.last.group && !step.groups.include?(hierarhy.last.group)
            hierarhy.pop
          end
          if hierarhy.last.group == step.groups.last
            hierarhy.last.items << step
          else
            group_rest = step.groups.dup
            while hierarhy.last.group && group_rest.first != hierarhy.last.group
              group_rest.shift
            end
            group_rest.shift if group_rest.first == hierarhy.last.group
            group_rest.each do
              title = (hierarhy.map(&:group).compact + [_1]).map(&:title).join(': ')
              group = GroupTree.new(_1, [], title)
              hierarhy.last.items << group
              hierarhy << group
            end
            hierarhy.last.items << step
          end
          current_groups = step.groups
        end
      end
      return top
    end

    def walk_through(&block)
      items.each do |step|
        if step.is_a?(Lopata::StepExecution)
          yield step
        else # GroupTree
          group = step
          go_dipper = yield group
          group.walk_through(&block) if go_dipper
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lopata-0.1.25 lib/lopata/observers/group_tree.rb
lopata-0.1.24 lib/lopata/observers/group_tree.rb
lopata-0.1.23 lib/lopata/observers/group_tree.rb
lopata-0.1.22 lib/lopata/observers/group_tree.rb