Sha256: 1cbc9d401a6d1a30163f0d9bf1d07526009b1d6e57c1193105b8c107e3da038d

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

module Remocon
  class ConditionFileInterpreter
    SUPPORTED_ATTRIBUTED = %i[name expression tagColor]

    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|
        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

      [json_array, errors]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remocon-0.1.0 lib/remocon/interpreter/condition_file_interpreter.rb