Class: Natsukantou::Setup::ConfigLoadOrPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/natsukantou/setup/config_load_or_prompt.rb

Instance Method Summary collapse

Instance Method Details

#execute(prompt:, config_path:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/natsukantou/setup/config_load_or_prompt.rb', line 6

def execute(prompt:, config_path:)
  begin
    load(config_path) if config_path
  rescue LoadError # rubocop:disable Lint/SuppressedException
  end

  if !defined?(NatsukantouTranslator)
    require_relative 'config_prompt'
    config_content = ConfigPrompt.new.execute

    if prompt.yes?("\nConfig complete. Do you want to save it for later reuse?")
      File.write('translator_config.rb', config_content)
      puts "Saved as translator_config.rb, which you can specify with -c flag next time.\n\n"
    end

    Kernel.eval(config_content)
  end

  NatsukantouTranslator
end