Class: RailsConsolePro::Commands::SnippetsCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/rails_console_pro/commands/snippets_command.rb

Overview

Command for managing, searching, and listing reusable console snippets

Constant Summary collapse

DEFAULT_LIST_LIMIT =
10

Instance Method Summary collapse

Methods included from RailsConsolePro::ColorHelper

#bold_color, #color, #method_missing, #pastel, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsConsolePro::ColorHelper

Instance Method Details

#execute(action = :list, *args, **kwargs, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_console_pro/commands/snippets_command.rb', line 9

def execute(action = :list, *args, **kwargs, &block)
  return disabled_message unless enabled?

  action = infer_action(action, args)
  case action
  when :list
    list_snippets(**kwargs)
  when :search
    search_snippets(*args, **kwargs)
  when :add, :create
    add_snippet(*args, **kwargs, &block)
  when :show
    show_snippet(*args)
  when :delete, :remove
    delete_snippet(*args)
  when :favorite
    toggle_favorite(*args, value: true)
  when :unfavorite
    toggle_favorite(*args, value: false)
  else
    pastel.red("Unknown snippets action: #{action}")
  end
rescue ArgumentError => e
  pastel.red("Snippets error: #{e.message}")
end