Sha256: 4aa9463508cb7bf72e47c5fd3f3f95555eb721c3d0cb4f9484895b74a6a8db12

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'singleton'
require 'inifile'
require 'rainbow'

# Global parameters
class Application
  include Singleton

  VERSION = '2.2.0'        # Application version
  NAME = 'asker'           # Application name
  HOMEPAGE = "https://github.com/dvarrui/#{NAME}/tree/v2.2"
  GEM = 'asker-tool'       # Gem name
  CONFIGFILE = 'asker.ini' # Config filename
  attr_reader :config

  ##
  # Initialize Application singleton
  def initialize
    reset
  end

  ##
  # Initialize config values from external "config.ini" file.
  # rubocop:disable Metrics/AbcSize
  # rubocop:disable Metrics/MethodLength
  def reset
    filename = File.join(Dir.pwd, CONFIGFILE)
    filename = File.join(File.dirname(__FILE__), 'files', CONFIGFILE) unless File.exist? filename

    begin
      @config = IniFile.load(filename)
    rescue StandardError => e
      puts e.display
      puts Rainbow('[ERROR] Revise configuration file:').red.bright
      puts Rainbow("        #{filename}").red.bright
      exit 1
    end
    stages = @config['questions']['stages'].split(',')
    @config['questions']['stages'] = stages.map(&:to_sym)
    Rainbow.enabled = false
    Rainbow.enabled = true if @config['global']['color'].downcase == 'yes'
  end
  # rubocop:enable Metrics/MethodLength
  # rubocop:enable Metrics/AbcSize
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
asker-tool-2.2.0 lib/asker/application.rb