Sha256: 935a3036ebb7c435f8851bff273ff28cd3652aaaeac68bc309c1bc88d69e0ec2

Contents?: true

Size: 1.26 KB

Versions: 19

Compression:

Stored size: 1.26 KB

Contents

module Evertils
  class Cfg
    # Perform first run tasks and create or read config file values
    def bootstrap!
      populate_config

      return if valid_config?

      # no config file found, lets create one using the firstrun controller
      require 'client/controller/firstrun'

      controller = Evertils::Controller::Firstrun.new
      controller.default

      populate_config
    end

    # Returns a hash of all module constants and their values
    def options
      keys = Evertils.constants.select { |name| constant?(name) }
      hash = {}

      keys.each { |key| hash[key] = Evertils.const_get(key) }
      hash
    end

    # Populates the internal hash which stores any values set in the config file
    def populate_config
      file = File.expand_path("~/.evertils/config.yml")
      fmt = Evertils::Helper.load('Formatting')

      @yml = fmt.symbolize(::YAML.load_file(file))
      self
    end

    # Get a specific value from the config file data
    # Params:
    # +name+:: String/symbol key value
    def get(name)
      @yml[name.to_sym]
    end

    private

    # Check if configuration data exists
    def valid_config?
      !@yml.nil?
    end

    # Checks if string is a constant
    def constant?(name)
      name == name.upcase
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
evertils-0.3.25 lib/evertils/config.rb
evertils-0.3.24 lib/evertils/config.rb
evertils-0.3.23 lib/evertils/config.rb
evertils-0.3.22 lib/evertils/config.rb
evertils-0.3.21 lib/evertils/config.rb
evertils-0.3.20 lib/evertils/config.rb
evertils-0.3.19 lib/evertils/config.rb
evertils-0.3.18 lib/evertils/config.rb
evertils-0.3.17 lib/evertils/config.rb
evertils-0.3.16 lib/evertils/config.rb
evertils-0.3.15 lib/evertils/config.rb
evertils-0.3.14.1 lib/evertils/config.rb
evertils-0.3.14 lib/evertils/config.rb
evertils-0.3.13 lib/evertils/config.rb
evertils-0.3.12 lib/evertils/config.rb
evertils-0.3.11 lib/evertils/config.rb
evertils-0.3.10 lib/evertils/config.rb
evertils-0.3.9 lib/evertils/config.rb
evertils-0.3.8 lib/evertils/config.rb