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.6.4 lib/fwtoolkit/configfile.rb
fwtoolkit-2.6.3 lib/fwtoolkit/configfile.rb
fwtoolkit-2.6.2 lib/fwtoolkit/configfile.rb
fwtoolkit-2.6.1 lib/fwtoolkit/configfile.rb
fwtoolkit-2.6.0 lib/fwtoolkit/configfile.rb
fwtoolkit-2.5.0 lib/fwtoolkit/configfile.rb
fwtoolkit-2.4.0 lib/fwtoolkit/configfile.rb
fwtoolkit-2.3.6 lib/fwtoolkit/configfile.rb
fwtoolkit-2.3.5 lib/fwtoolkit/configfile.rb
fwtoolkit-2.3.4 lib/fwtoolkit/configfile.rb
fwtoolkit-2.3.3 lib/fwtoolkit/configfile.rb
fwtoolkit-2.3.2 lib/fwtoolkit/configfile.rb
fwtoolkit-2.3.1 lib/fwtoolkit/configfile.rb
fwtoolkit-2.3.0 lib/fwtoolkit/configfile.rb
fwtoolkit-2.2.4 lib/fwtoolkit/configfile.rb
fwtoolkit-2.2.3 lib/fwtoolkit/configfile.rb
fwtoolkit-2.2.2 lib/fwtoolkit/configfile.rb
fwtoolkit-2.2.1 lib/fwtoolkit/configfile.rb
fwtoolkit-2.2.0 lib/fwtoolkit/configfile.rb
fwtoolkit-2.1.10 lib/fwtoolkit/configfile.rb