Sha256: 5d9a8c3a4768af738ed8fbcc37ebbf8989e63232d800f81bcfd88ce228a2d2f6

Contents?: true

Size: 615 Bytes

Versions: 6

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true

require "yaml"

module AIRefactor
  class CommandFileParser
    def self.command_file?(name)
      name.match?(/\.ya?ml$/)
    end

    def initialize(path)
      @path = path
    end

    def parse
      raise StandardError, "Invalid command file:  file does not exist" unless File.exist?(@path)

      options = YAML.safe_load_file(@path, permitted_classes: [Symbol], symbolize_names: true, aliases: true)

      unless options && options[:refactor]
        raise StandardError, "Invalid command file format, a 'refactor' key is required"
      end

      options
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ai_refactor-0.6.0 lib/ai_refactor/command_file_parser.rb
ai_refactor-0.5.4 lib/ai_refactor/command_file_parser.rb
ai_refactor-0.5.3 lib/ai_refactor/command_file_parser.rb
ai_refactor-0.5.2 lib/ai_refactor/command_file_parser.rb
ai_refactor-0.5.1 lib/ai_refactor/command_file_parser.rb
ai_refactor-0.5.0 lib/ai_refactor/command_file_parser.rb