Class: Flame::Application::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/flame/application.rb

Overview

Class for Flame::Application.config

Instance Method Summary collapse

Constructor Details

#initialize(app, hash = {}) ⇒ Config

Returns a new instance of Config.



83
84
85
86
# File 'lib/flame/application.rb', line 83

def initialize(app, hash = {})
	@app = app
	replace(hash)
end

Instance Method Details

#[](key) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/flame/application.rb', line 88

def [](key)
	result = super(key)
	if result.class <= Proc && result.parameters.empty?
		result = @app.class_exec(&result)
	end
	result
end

#load_yaml(file, key: nil, set: true) ⇒ Object

Method for loading YAML-files from config directory

Examples:

Load SMTP file from `config/smtp.yml' to config

config.load_yaml('smtp.yml')

Load SMTP file without extension, by Symbol

config.load_yaml(:smtp)

Load SMTP file with other key to config

config.load_yaml('smtp.yml', :mail)

Load SMTP file without allocating in config

config.load_yaml('smtp.yml', set: false)

Parameters:

  • file (String, Symbol) —

    file name (typecast to String with '.yml')

  • key (Symbol, String, nil) (defaults to: nil) —

    key for allocating YAML in config Hash (typecast to Symbol)

  • set (Boolean) (defaults to: true) —

    allocating YAML in Config Hash



109
110
111
112
113
114
115
116
# File 'lib/flame/application.rb', line 109

def load_yaml(file, key: nil, set: true)
	file = "#{file}.yml" if file.is_a? Symbol
	file_path = File.join(self[:config_dir], file)
	yaml = YAML.load_file(file_path)
	key ||= File.basename(file, '.*')
	self[key.to_sym] = yaml if set
	yaml
end