Sha256: 3b181f599ad7fb059557d784c2d52f8415ff19c11a5559a4e141708c80d19fd6

Contents?: true

Size: 1016 Bytes

Versions: 10

Compression:

Stored size: 1016 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'active_support/hash_with_indifferent_access'

module WatchTower
  module Config
    extend self

    # Define the config file's path
    CONFIG_FILE = File.join(USER_PATH, 'config.yml')

    # Define the config class variable
    @@config = nil

    # Return a particular config variable from the parsed config file
    #
    # @param [String|Symbol] config
    # @return mixed
    # @raise [Void]
    def [](config)
      ensure_config_file_exists
      @@config ||= HashWithIndifferentAccess.new(YAML.parse_file(CONFIG_FILE).to_ruby)
      @@config[:watch_tower].send(:[], config)
    end

    protected
      # Ensures config file exists in the user config folder
      #
      # @param [Void]
      # @return [Void]
      # @raise [Void]
      def ensure_config_file_exists
        unless File.exists?(CONFIG_FILE)
          File.open(CONFIG_FILE, 'w') do |f|
            f.write(File.read(File.join(TEMPLATE_PATH, 'config.yml')))
          end
        end
      end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
watch_tower-0.0.1.beta10 lib/watch_tower/config.rb
watch_tower-0.0.1.beta9 lib/watch_tower/config.rb
watch_tower-0.0.1.beta8 lib/watch_tower/config.rb
watch_tower-0.0.1.beta7 lib/watch_tower/config.rb
watch_tower-0.0.1.beta6 lib/watch_tower/config.rb
watch_tower-0.0.1.beta5 lib/watch_tower/config.rb
watch_tower-0.0.1.beta4 lib/watch_tower/config.rb
watch_tower-0.0.1.beta3 lib/watch_tower/config.rb
watch_tower-0.0.1.beta2 lib/watch_tower/config.rb
watch_tower-0.0.1.beta1 lib/watch_tower/config.rb