Sha256: aca943701c9e0cd12a086c21ff900d81523172b7ad86d69878d897b536b2cf6d
Contents?: true
Size: 1.74 KB
Versions: 2
Compression:
Stored size: 1.74 KB
Contents
module CouchRest::Model module Embeddable extend ActiveSupport::Concern # Include Attributes early to ensure super() will work include CouchRest::Attributes included do include CouchRest::Model::Configuration include CouchRest::Model::Properties include CouchRest::Model::PropertyProtection include CouchRest::Model::Associations include CouchRest::Model::Validations include CouchRest::Model::Callbacks include CouchRest::Model::CastedBy include CouchRest::Model::Dirty include CouchRest::Model::Callbacks class_eval do # Override CastedBy's base_doc? def base_doc? false # Can never be base doc! end end end # Initialize a new Casted Model. Accepts the same # options as CouchRest::Model::Base for preparing and initializing # attributes. def initialize(attributes = {}, options = {}) super() write_attributes_for_initialization(attributes, options) run_callbacks(:initialize) { self } end # False if the casted model has already # been saved in the containing document def new? casted_by.nil? ? true : casted_by.new? end alias :new_record? :new? def persisted? !new? end # The to_param method is needed for rails to generate resourceful routes. # In your controller, remember that it's actually the id of the document. def id return nil if base_doc.nil? base_doc.id end alias :to_key :id alias :to_param :id end # End Embeddable # Provide backwards compatability with previous versions (pre 1.1.0) module CastedModel extend ActiveSupport::Concern included do include CouchRest::Model::Embeddable end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
couchrest_model-2.2.0.beta2 | lib/couchrest/model/embeddable.rb |
couchrest_model-2.2.0.beta1 | lib/couchrest/model/embeddable.rb |