class GlobalSettings::YMLSettings
Public Class Methods
get(options)
click to toggle source
# File lib/global_settings/yml_settings.rb, line 4 def self.get(options) new(options).to_hash end
new(options)
click to toggle source
# File lib/global_settings/yml_settings.rb, line 8 def initialize(options) @root_path = options[:root_path] || guess_root_path || raise(ArgumentError.new("root_path must be specified")) @environment = options[:environment] || guess_environment || raise(ArgumentError.new("environment must be specified")) end
Public Instance Methods
to_hash()
click to toggle source
# File lib/global_settings/yml_settings.rb, line 18 def to_hash YAML.load_file(yml_settings_path).deep_symbolize_keys! rescue Errno::ENOENT puts "Could not load settings from settings.yml file for #{@environment} environment" {} end
Private Instance Methods
guess_environment()
click to toggle source
# File lib/global_settings/yml_settings.rb, line 40 def guess_environment case when defined? Rails Rails.env when defined? Sinatra::Application Sinatra::Application.environment else ENV['RACK_ENV'] end end
guess_root_path()
click to toggle source
# File lib/global_settings/yml_settings.rb, line 31 def guess_root_path case when defined? Rails Rails.root when defined? Sinatra::Application Sinatra::Application.root end end
yml_settings_path()
click to toggle source
# File lib/global_settings/yml_settings.rb, line 27 def yml_settings_path File.join(@root_path, 'config', 'settings', "#{@environment}.yml") end