Method: SimpleRecord::ActiveSdb::Base#save2

Defined in:
lib/simple_record/active_sdb.rb

#save2(options = {}) ⇒ Object

Store in-memory attributes to SDB. Replaces the attributes values already stored at SDB by in-memory data. Returns a hash of stored attributes.

sandy = Client.new(:name => 'Sandy')  #=> #<Client:0xb775a7a8 @attributes={"name"=>["Sandy"]}, @new_record=true>
sandy['toys'] = 'boys'
sandy.save
sandy['toys'] = 'patchwork'
sandy.save
sandy['toys'] = 'kids'
sandy.save
puts sandy.attributes.inspect         #=> {"name"=>["Sandy"], "id"=>"b2832ce2-e461-11dc-b13c-001bfc466dd7", "toys"=>["kids"]}
sandy.reload                          #=> {"name"=>["Sandy"], "id"=>"b2832ce2-e461-11dc-b13c-001bfc466dd7", "toys"=>["kids"]}

Options:

- :except => Array of attributes to NOT save

compare to put method



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
# File 'lib/simple_record/active_sdb.rb', line 859

def save2(options={})
    options[:create_domain] = true if options[:create_domain].nil?
    pre_save2
    atts_to_save = @attributes.dup
    #puts 'atts_to_save=' + atts_to_save.inspect
    #options = params.first.is_a?(Hash) ? params.pop : {}
    if options[:except]
        options[:except].each do |e|
            atts_to_save.delete(e).inspect
        end
    end
    if options[:dirty] # Only used in simple_record right now
        # only save if the attribute is dirty
        dirty_atts = options[:dirty_atts]
        atts_to_save.delete_if { |key, value| !dirty_atts.has_key?(key) }
    end
    dom          = options[:domain] || domain
    #puts 'atts_to_save2=' + atts_to_save.inspect
    connection.put_attributes(dom, id, atts_to_save, :replace, options)
    apres_save2
    @attributes
end