lib/baurets/optionsful/config.rb in optionsful-0.1.7 vs lib/baurets/optionsful/config.rb in optionsful-0.1.8
- old
+ new
@@ -1,35 +1,49 @@
module Baurets
module Optionsful
-
class Config
- def initialize
- # Initialize default settings- May be overriden if RAILS_ROOT/config/optionsful.yml exists.
- @config = { :http => {:base_path => "/optionsful"} }
+ def initialize(options = {})
+ @config = configure_options(options)
setup
+ self
end
+ def base_path
+ @config[:http][:base_path]
+ end
+
+ private
+
+ def configure_options(options = {})
+ default_opts = { :http => { :base_path => "/optionsful"}, :file => "", :environment => "development" }
+ conf = {}
+ if defined? RAILS_ROOT
+ conf = default_opts.merge!({:file => (File.join(RAILS_ROOT, 'config', 'optionsful.yml'))})
+ else
+ conf = default_opts.merge!({ :http => { :base_path => "/optionsful"} })
+ end
+ conf = conf.merge!(options) unless options.empty?
+ conf
+ end
+
def setup
require "yaml"
+ yaml_file = @config[:file]
begin
- yaml_file = File.join(RAILS_ROOT, "config", "optionsful.yml")
if File.exist? yaml_file
- conf = YAML::load_file(yaml_file)[RAILS_ENV].symbolize_keys
+ conf = YAML::load_file(yaml_file)[@config[:environment]].symbolize_keys
configure(conf) if conf
end
rescue
end
end
+
def configure(conf)
- @config[:http][:base_path] = conf[:http][:base_path] if (conf[:http] && conf[:http][:base_path])
+ @config[:http][:base_path] = conf[:http]["base_path"] if (conf[:http] && conf[:http]["base_path"])
+ @config[:file] = conf[:file] if conf[:file]
+ @config[:environment] = conf[:environment] if conf[:environment]
end
-
- def base_path
- @config[:http][:base_path]
- end
-
end
-
end
end
\ No newline at end of file