lib/morpheus/mixins/persistence.rb in morpheus-0.3.6 vs lib/morpheus/mixins/persistence.rb in morpheus-0.3.7

- old
+ new

@@ -1,37 +1,36 @@ module Morpheus module Persistence - extend ActiveSupport::Concern - module InstanceMethods + def self.included(base) + base.extend(ClassMethods) + end - def save(with_validations = true) - attributes_for_save = { self.class.attributes_root => attributes_without_basic_attributes.reject { |k,v| v.nil? } } + def save(with_validations = true) + attributes_for_save = { self.class.attributes_root => attributes_without_basic_attributes.reject { |k,v| v.nil? } } - if with_validations - return false unless valid? - end - - if new_record? - built_object = self.class.post(*UrlBuilder.save(self.class, nil, attributes_for_save)) - else - built_object = self.class.put(*UrlBuilder.save(self.class, id, attributes_for_save)) - end - built_object.instance_variables.each do |iv| - self.instance_variable_set(iv, built_object.instance_variable_get(iv)) - end - @valid + if with_validations + return false unless valid? end - def update_attributes(new_attributes) - merge_attributes(new_attributes) - save + if new_record? + built_object = self.class.post(*UrlBuilder.save(self.class, nil, attributes_for_save)) + else + built_object = self.class.put(*UrlBuilder.save(self.class, id, attributes_for_save)) end - - def destroy - self.class.delete(UrlBuilder.destroy(self.class, id)) + built_object.instance_variables.each do |iv| + self.instance_variable_set(iv, built_object.instance_variable_get(iv)) end + @valid + end + def update_attributes(new_attributes) + merge_attributes(new_attributes) + save + end + + def destroy + self.class.delete(UrlBuilder.destroy(self.class, id)) end module ClassMethods def create(new_attributes = {})