lib/chimera/base.rb in chimera-0.0.3 vs lib/chimera/base.rb in chimera-0.0.4

- old
+ new

@@ -20,30 +20,33 @@ extend ActiveModel::Naming extend ActiveModel::Callbacks define_model_callbacks :create, :save, :destroy - attr_accessor :id, :attributes, :orig_attributes, :riak_response, :associations + attr_accessor :id, :attributes, :orig_attributes, :riak_response, :associations, + :sibling_attributes def self.use_config(key) @config = (Chimera.config[key.to_sym] || raise(Chimera::Error::MissingConfig,":#{key}")) end def self.config @config ||= (Chimera.config[:default] || raise(Chimera::Error::MissingConfig,":default")) end def self.connection(server) - Thread.current["Chimera::#{self.to_s}::#{server}::connection"] ||= begin - case server.to_sym - when :redis - Redis.new(self.config[:redis]) - when :riak_raw - RiakRaw::Client.new(self.config[:riak_raw][:host], self.config[:riak_raw][:port]) - else - nil - end + Thread.current["Chimera::#{self.to_s}::#{server}::connection"] ||= new_connection(server) + end + + def self.new_connection(server) + case server.to_sym + when :redis + Redis.new(self.config[:redis]) + when :riak_raw + RiakRaw::Client.new(self.config[:riak_raw][:host], self.config[:riak_raw][:port]) + else + nil end end def self.bucket_key self.to_s @@ -74,9 +77,10 @@ def initialize(attributes={},id=nil,is_new=true) @attributes = attributes @orig_attributes = @attributes.clone @id = id @new = is_new + @sibling_attributes = nil end def id=(val) if self.new? @id = val \ No newline at end of file