Sha256: a1098bdbce714ff520d63d05373b32c0f0d78b4e956f3e8a1f2ef93249da1088

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

require_relative 'value_replacer'
require_relative 'mismatched_variable_finder'
require_relative 'prompter'
require_relative 'env_appender'

module Dotenvious
  class Prompter
    def self.run
      keys_in_question.each do |key, status|
        decision = prompt(key, status)
        return if decision == 'q'
        next unless decision.downcase == 'y'

        if status == 'missing'
          EnvAppender.new.append(key)
        elsif status == 'mismatched'
          ValueReplacer.new.replace(key)
        end
      end
    end

    private

    def self.keys_in_question
      missing_keys = missing_vars.zip(['missing'] * missing_vars.length)
      mismatched_keys = mismatched_vars.zip(['mismatched'] * mismatched_vars.length)
      missing_keys + mismatched_keys
    end

    def self.missing_vars
      MissingVariableFinder.missing_required_vars
    end

    def self.mismatched_vars
      MismatchedVariableFinder.mismatched_vars
    end

    def self.prompt(var, status)
      send(:"display_#{status}_output", var)
      STDIN.gets.strip
    end

    def self.display_missing_output(var)
      puts "#{var}=#{ENV_EXAMPLE[var]}"
      puts "Add to .env? [y/n/q]"
    end

    def self.display_mismatched_output(var)
      puts "ENV[#{var}] is set to: #{ENV[var]}"
      puts "Example [#{var}] is set to: #{ENV_EXAMPLE[var]}"
      puts "Replace with the example value? [y/n/q]"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dotenvious-0.0.6 lib/dotenvious/prompter.rb
dotenvious-0.0.5 lib/dotenvious/prompter.rb
dotenvious-0.0.4 lib/dotenvious/prompter.rb
dotenvious-0.0.3 lib/dotenvious/prompter.rb
dotenvious-0.0.1 lib/dotenvious/prompter.rb