Sha256: 9e16d8100f0c55879b0efe8a37f7d355b14a6adb371e5be3e9acd555dc94e202

Contents?: true

Size: 853 Bytes

Versions: 6

Compression:

Stored size: 853 Bytes

Contents

require 'fwtoolkit/ext/hash_yaml'

# Mixin module that reads a yaml file into a hash and responds to config values
module FWToolkit
  module ConfigFile

    attr_accessor :default_config

    def config
      @config ||= Hash.new
    end

    def load_config_hash!(config)
      @config = config
      merge_config @default_config if @default_config
      validate_config if self.method_defined? :validate_config
    end

    def load_config!(config_file)
      load_config_hash! Hash.hash_from_yaml(config_file)
    end

    def merge_config(default_config)
      default_config.each { |key, value| config[key] ||= value }
    end

    def configure
      yield config
    end

    def method_missing(name, *args, &block)
      puts name
      config[name.to_sym] || conf_item_missing(name) if self.method_defined? :conf_item_missing
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fwtoolkit-1.0.6 lib/fwtoolkit/configfile.rb
fwtoolkit-1.0.5 lib/fwtoolkit/configfile.rb
fwtoolkit-1.0.4 lib/fwtoolkit/configfile.rb
fwtoolkit-1.0.3 lib/fwtoolkit/configfile.rb
fwtoolkit-1.0.2 lib/fwtoolkit/configfile.rb
fwtoolkit-1.0.1 lib/fwtoolkit/configfile.rb