Sha256: 5a8941f5cb1638bdd4deb5058c9866645c08c5a73f428997fa2e3021f16c0ab4

Contents?: true

Size: 837 Bytes

Versions: 36

Compression:

Stored size: 837 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)
      config[name.to_sym] || conf_item_missing(name) if self.method_defined? :conf_item_missing
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
fwtoolkit-2.1.9 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.8 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.7 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.6 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.5 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.4 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.3 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.1 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.7 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.6 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.5 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.4 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.3 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.2 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.1 lib/fwtoolkit/configfile.rb
fwtoolkit-2.0.0 lib/fwtoolkit/configfile.rb