lib/architect4r/model/persistency.rb in architect4r-0.4.3 vs lib/architect4r/model/persistency.rb in architect4r-0.4.3.1
- old
+ new
@@ -1,68 +1,60 @@
module Architect4r
module Model
module Persistency
extend ActiveSupport::Concern
- included do
-
+ # Creates the document in the db. Raises an exception
+ # if the document is not created properly.
+ def create!(options = {})
+ self.fail_validate!(self) unless self.create(options)
end
- module InstanceMethods
-
- # Creates the document in the db. Raises an exception
- # if the document is not created properly.
- def create!(options = {})
- self.fail_validate!(self) unless self.create(options)
- end
-
- def save(options = {})
- self.new? ? create(options) : update(options)
- end
+ def save(options = {})
+ self.new? ? create(options) : update(options)
+ end
- def save!
- self.class.fail_validate!(self) unless self.save
- true
+ def save!
+ self.class.fail_validate!(self) unless self.save
+ true
+ end
+
+ def id
+ @id ||= if raw_data && raw_data['self'].present?
+ raw_data['self'].split('/').last.to_i
+ else
+ nil
end
-
- def id
- @id ||= if raw_data && raw_data['self'].present?
- raw_data['self'].split('/').last.to_i
- else
- nil
- end
- end
- alias :to_key :id
- alias :to_param :id
+ end
+ alias :to_key :id
+ alias :to_param :id
- def new?
- # Persisted objects always have an id.
- id.nil?
- end
- alias :new_record? :new?
+ def new?
+ # Persisted objects always have an id.
+ id.nil?
+ end
+ alias :new_record? :new?
- def destroyed?
- !!@_destroyed
- end
+ def destroyed?
+ !!@_destroyed
+ end
- def persisted?
- !new? && !destroyed?
- end
+ def persisted?
+ !new? && !destroyed?
+ end
- # Update the document's attributes and save. For example:
- def update_attributes(hash)
- update_attributes_without_saving hash
- save
- end
+ # Update the document's attributes and save. For example:
+ def update_attributes(hash)
+ update_attributes_without_saving hash
+ save
+ end
- protected
+ protected
- def perform_validations(options = {})
- (options[:validate].presence || true) ? valid? : true
- end
-
+ def perform_validations(options = {})
+ (options[:validate].presence || true) ? valid? : true
end
-
+
module ClassMethods
def create(*args, &block)
instance = new(*args, &block)
instance.create
\ No newline at end of file