lib/ripple.rb in ripple-0.7.1 vs lib/ripple.rb in ripple-0.8.0.beta

- old
+ new

@@ -14,16 +14,16 @@ require 'riak' require 'active_support/all' require 'active_model' require 'ripple/i18n' +require 'ripple/core_ext' # Contains the classes and modules related to the ODM built on top of # the basic Riak client. module Ripple extend ActiveSupport::Autoload - include ActiveSupport::Configurable # Primary models autoload :EmbeddedDocument autoload :Document @@ -40,14 +40,13 @@ # Exceptions autoload :PropertyTypeMismatch # Utilities + autoload :Inspection autoload :Translation - DEFAULT_CONFIG = {} - class << self # @return [Riak::Client] The client for the current thread. def client Thread.current[:ripple_client] ||= Riak::Client.new(config) end @@ -58,13 +57,32 @@ Thread.current[:ripple_client] = value end def config=(hash) self.client = nil - super + @config = hash.symbolize_keys end - def load_config(config_file) - self.config = YAML.load_file(File.expand_path config_file).with_indifferent_access[:ripple] + def config + @config ||= {} end + + def load_configuration(config_file, config_keys = [:ripple]) + config_file = File.expand_path(config_file) + config_hash = YAML.load(ERB.new(File.read(config_file)).result).with_indifferent_access + config_keys.each {|k| config_hash = config_hash[k]} + self.config = config_hash || {} + rescue Errno::ENOENT + raise Ripple::MissingConfiguration.new(config_file) + end + alias_method :load_config, :load_configuration end + + class MissingConfiguration < StandardError + include Translation + def initialize(file_path) + super(t("missing_configuration", :file => file_path)) + end + end end + +require 'ripple/railtie' if defined? Rails::Railtie