Sha256: 35c275cd5c567ab3a3c221ae4ebd907a409045f39ab58cec9872fcfa5d1db2dd

Contents?: true

Size: 943 Bytes

Versions: 11

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

module Remocon
  class ConditionFileInterpreter
    SUPPORTED_ATTRIBUTED = %i(name expression tagColor).freeze

    def initialize(filepath)
      # conditions should be Array
      @yaml = YAML.safe_load(File.open(filepath).read).map(&:with_indifferent_access)
    end

    def read(opts = {})
      errors = []
      json_array = @yaml.dup

      keys = []

      @yaml.each do |hash|
        begin
          raise Remocon::EmptyNameError, "name must not be empty" unless hash[:name]
          raise Remocon::EmptyExpressionError, "expression must not be empty" unless hash[:expression]
          raise Remocon::DuplicateKeyError, "#{hash[:name]} is duplicated" if keys.include?(hash[:name])

          keys.push(hash[:name])
        rescue Remocon::ValidationError => e
          raise e unless opts[:validate_only]
          errors.push(e)
        end
      end

      [json_array, errors]
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
remocon-0.5.1 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.5.0 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.4.4 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.4.3 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.4.2 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.4.1 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.4.0 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.4.0.pre.1 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.3.1 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.3.0 lib/remocon/interpreter/condition_file_interpreter.rb
remocon-0.2.0 lib/remocon/interpreter/condition_file_interpreter.rb