Module: BigBand::ConfigFile
- Defined in:
- lib/big_band/config_file.rb
Overview
Using YAML config files. Config files are expected to represent hashes. When parsing such a config file it will use set to store that value, ignoring those directly defined in the app (not those defined by the class it inherits from, i.e. Sinatra::Base or BigBand).
Example:
class MyApp << BigBand
set :foo, "bar"
config_file "settings.yml" # general settings
config_file "#{environment}.settings.yml" # environment specific settings
foo # => "bar"
end
Now you could write in your settings.yml:
---
server: [thin, webrick] # use only thin or webrick for #run!
public: /var/www # load public files from /var/www
port: 8080 # run on port 8080
foo: baz
database:
adapter: sqlite
In you development.settings.yml:
database:
db_file: development.db
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.registered(klass) ⇒ Object
35 36 37 |
# File 'lib/big_band/config_file.rb', line 35 def self.registered(klass) klass.register BasicExtensions end |
Instance Method Details
#config_file(*paths) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/big_band/config_file.rb', line 39 def config_file(*paths) paths.each do |pattern| files = root_glob(pattern.to_s) files.each { |f| YAML.load_file(f).each_pair { |k,v| set k, v unless methods(false).any? { |m| m.to_s = k.to_s } } } warn "WARNING: could not load config file #{pattern}" if files.empty? end end |