Support for handling attributes
This would be better in the properties file, but due to scoping issues this is not yet possible.
# File lib/couchrest/mixins/attributes.rb, line 11 def prepare_all_attributes(doc = {}, options = {}) apply_all_property_defaults if options[:directly_set_attributes] directly_set_read_only_attributes(doc) else remove_protected_attributes(doc) end directly_set_attributes(doc) unless doc.nil? end
Takes a hash as argument, and applies the values by using writer methods for each key. Raises a NoMethodError if the corresponding methods are missing. In case of error, no attributes are changed.
# File lib/couchrest/mixins/attributes.rb, line 35 def update_attributes(hash) update_attributes_without_saving hash save end
Takes a hash as argument, and applies the values by using writer methods for each key. It doesn’t save the document at the end. Raises a NoMethodError if the corresponding methods are missing. In case of error, no attributes are changed.
# File lib/couchrest/mixins/attributes.rb, line 24 def update_attributes_without_saving(hash) # Remove any protected and update all the rest. Any attributes # which do not have a property will simply be ignored. attrs = remove_protected_attributes(hash) directly_set_attributes(attrs) end