class Configurative::SettingsLoader
Public Class Methods
new(options={})
click to toggle source
# File lib/configurative/settings_loader.rb, line 8 def initialize(options={}) @options = {}.merge(options) end
Public Instance Methods
load!(path)
click to toggle source
# File lib/configurative/settings_loader.rb, line 12 def load!(path) type = MIME::Types.type_for(path).first.content_type case type when "application/json" load_json_file!(path) when "text/x-yaml" load_yaml_file!(path) else raise ConfigurationError, "Unsupported confguration file type '#{type}' encountered." end end
Private Instance Methods
environment()
click to toggle source
# File lib/configurative/settings_loader.rb, line 26 def environment (@options[:environment] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development") end
extract_settings(input)
click to toggle source
# File lib/configurative/settings_loader.rb, line 46 def extract_settings(input) settings = {}.merge(input) settings = settings[environment] if settings.include?(environment) settings = settings[section] if section && settings.include?(section) SettingsParser.new(@options).parse(settings) end
load_json_file!(path)
click to toggle source
# File lib/configurative/settings_loader.rb, line 40 def load_json_file!(path) extract_settings(JSON.parse(ERB.new(File.read(path)).result)) rescue => error raise ConfigurationError.new("Exception caught loading the '#{path}' configuration file.", error) end
load_yaml_file!(path)
click to toggle source
# File lib/configurative/settings_loader.rb, line 34 def load_yaml_file!(path) extract_settings(YAML.load(ERB.new(File.read(path)).result)) rescue => error raise ConfigurationError.new("Exception caught loading the '#{path}' configuration file.", error) end
section()
click to toggle source
# File lib/configurative/settings_loader.rb, line 30 def section (@options[:section] || nil) end