Sha256: c510377a8fc35acfd26c8a5041f00c5cddca2ad46b82c08d8da4be325ba4ada7

Contents?: true

Size: 825 Bytes

Versions: 4

Compression:

Stored size: 825 Bytes

Contents

module Lopata
  # @private
  class Condition
    attr_reader :condition, :positive
    def initialize(condition, positive: true)
      @condition, @positive = condition, positive
    end

    alias positive? positive

    def match?(scenario)
      matched = match_metadata?(scenario)
      positive? ? matched : !matched
    end

    def match_metadata?(scenario)
      metadata = scenario.metadata
      case condition
      when Hash
        condition.keys.all? do |k| 
          if condition[k].is_a? Array
            condition[k].include?(metadata[k])
          else
            metadata[k] == condition[k]
          end
        end
      when Array
        condition.map { |key| metadata[key] }.all?
      when TrueClass, FalseClass
        condition
      else
        metadata[condition]
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lopata-0.1.22 lib/lopata/condition.rb
lopata-0.1.21 lib/lopata/condition.rb
lopata-0.1.20 lib/lopata/condition.rb
lopata-0.1.19 lib/lopata/condition.rb