Module: AIRefactor::Commands

Defined in:
lib/ai_refactor/commands.rb

Constant Summary collapse

BuiltInCommand =

TODO: support command_line_options

Data.define(:name, :description, :path, :command_line_options, :config)

Class Method Summary collapse

Class Method Details

.allObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ai_refactor/commands.rb', line 28

def all
  @all ||= begin
    commands = Dir.glob(File.join(__dir__, "../../commands", "**/*.yml")).map do |path|
      path_to_commands = File.join(__dir__, "../../commands/")
      name = File.join(File.dirname(path.gsub(path_to_commands, "")), File.basename(path, ".yml")).to_sym
      config = YAML.safe_load_file(path, permitted_classes: [Symbol], symbolize_names: true, aliases: true)
      BuiltInCommand.new(name: name, path: path, description: config[:description], config: config, command_line_options: [])
    end
    commands.map { |c| [c.name, c] }.to_h
  end
end

.descriptionsObject



18
19
20
# File 'lib/ai_refactor/commands.rb', line 18

def descriptions
  names.map { |n| "\"#{n}\"" }.zip(all.values.map(&:description)).to_h
end

.get(name) ⇒ Object



8
9
10
# File 'lib/ai_refactor/commands.rb', line 8

def get(name)
  all[name]
end

.namesObject



13
14
15
# File 'lib/ai_refactor/commands.rb', line 13

def names
  all.keys
end

.supported?(name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ai_refactor/commands.rb', line 23

def supported?(name)
  names.include?(name)
end