Sha256: b53927a92dce51a55b8f98355320687b26e532ecd5fdee58c6a3b651e2fe5f77

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

module ATP
  module Validators
    class Flags < Validator
      def setup
        @open_if_nodes = []
        @open_unless_nodes = []
        @conflicting = []
      end

      def on_completion
        failed = false
        unless @conflicting.empty?
          error 'if_flag and unless_flag conditions cannot be nested and refer to the same flag unless it is declared as volatile'
          error "The following conflicts were found in flow #{flow.name}:"
          @conflicting.each do |a, b|
            a_condition = a.to_a[1] ? 'if_job:    ' : 'unless_job:'
            b_condition = b.to_a[1] ? 'if_job:    ' : 'unless_job:'
            error "  #{a.type}(#{a.to_a[0]}) #{a.source}"
            error "  #{b.type}(#{b.to_a[0]}) #{b.source}"
            error ''
          end
          failed = true
        end
        failed
      end

      def on_flow(node)
        extract_volatiles(node)
        process_all(node.children)
      end

      def on_if_flag(node)
        if volatile?(node.to_a[0])
          process_all(node.children)
        else
          if n = @open_unless_nodes.find { |n| n.to_a[0] == node.to_a[0] }
            @conflicting << [n, node]
          end
          @open_if_nodes << node
          process_all(node.children)
          @open_if_nodes.pop
        end
      end

      def on_unless_flag(node)
        if volatile?(node.to_a[0])
          process_all(node.children)
        else
          if n = @open_if_nodes.find { |n| n.to_a[0] == node.to_a[0] }
            @conflicting << [n, node]
          end
          @open_unless_nodes << node
          process_all(node.children)
          @open_unless_nodes.pop
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
atp-1.1.3 lib/atp/validators/flags.rb
atp-1.1.2 lib/atp/validators/flags.rb
atp-1.1.1 lib/atp/validators/flags.rb
atp-1.1.0 lib/atp/validators/flags.rb