Class: RailsInteractive::CLI::CommandHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/command_handler.rb

Overview

Commands class for the interactive CLI module

Instance Method Summary collapse

Constructor Details

#initializeCommandHandler

Returns a new instance of CommandHandler.



10
11
12
13
14
# File 'lib/cli/command_handler.rb', line 10

def initialize
  @commands = Command.new.all
  @installed_commands = []
  @installed_dependencies = []
end

Instance Method Details

#handle_dependencies(dependencies) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/cli/command_handler.rb', line 32

def handle_dependencies(dependencies)
  dependencies&.each do |dependency|
    next if duplicated_gem?(dependency)

    puts ">> Dependency Detected: #{dependency} "
    @installed_dependencies << dependency

    system("bin/rails app:template LOCATION=templates/setup_#{dependency}.rb")
  end
end

#handle_multi_options(options, dependencies = nil) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/cli/command_handler.rb', line 16

def handle_multi_options(options, dependencies = nil)
  handle_dependencies(dependencies)

  options.each do |option|
    @installed_commands << option
    system("bin/rails app:template LOCATION=templates/setup_#{option}.rb")
  end
end

#handle_option(option, dependencies = nil) ⇒ Object



25
26
27
28
29
30
# File 'lib/cli/command_handler.rb', line 25

def handle_option(option, dependencies = nil)
  @installed_commands << option
  handle_dependencies(dependencies)

  system("bin/rails app:template LOCATION=templates/setup_#{option}.rb")
end