module SimpleRailsConfigurator
Constants
- VERSION
Public Class Methods
configure!(path=nil)
click to toggle source
# File lib/simple_rails_configurator.rb, line 4 def self.configure!(path=nil) path ||= Rails.root.join('config', 'custom') files = Dir.glob(File.join(path, '**', '*.{yml,yaml}')) files.each{ |file| configure_from_file(file) } end
configure_from_file(filename)
click to toggle source
# File lib/simple_rails_configurator.rb, line 11 def self.configure_from_file(filename) # TODO: Pass down a path prefix and implement "namespaces" based on location? yaml = load_config_yaml(filename) if is_local? override = load_config_yaml("#{filename}.override") yaml.merge!(override) end name = File.basename(filename).rpartition('.')[0] Rails.application.config.send("#{name}=".to_sym, yaml) end
is_local?()
click to toggle source
# File lib/simple_rails_configurator.rb, line 35 def self.is_local? Rails.env.development? || Rails.env.local? end
load_config_yaml(filename)
click to toggle source
# File lib/simple_rails_configurator.rb, line 24 def self.load_config_yaml(filename) if File.exist?(filename) config_erb = ERB.new(File.read(filename)) yaml = YAML.load(config_erb.result) return yaml[Rails.env] if yaml.key?(Rails.env) return yaml end return {} end