Class: AIRefactor::CommandFileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ai_refactor/command_file_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CommandFileParser

Returns a new instance of CommandFileParser.



11
12
13
# File 'lib/ai_refactor/command_file_parser.rb', line 11

def initialize(path)
  @path = path
end

Class Method Details

.command_file?(name) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/ai_refactor/command_file_parser.rb', line 7

def self.command_file?(name)
  name.match?(/\.ya?ml$/)
end

Instance Method Details

#parseObject

Raises:

  • (StandardError)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ai_refactor/command_file_parser.rb', line 15

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