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
- .all ⇒ Object
- .descriptions ⇒ Object
- .get(name) ⇒ Object
- .names ⇒ Object
- .supported?(name) ⇒ Boolean
Class Method Details
.all ⇒ Object
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 |
.descriptions ⇒ Object
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 |
.names ⇒ Object
13 14 15 |
# File 'lib/ai_refactor/commands.rb', line 13 def names all.keys end |
.supported?(name) ⇒ Boolean
23 24 25 |
# File 'lib/ai_refactor/commands.rb', line 23 def supported?(name) names.include?(name) end |