Sha256: f08e033ad13c45cf869e12a12c22bfb79303d31c359c4481e56997eccd009ae4

Contents?: true

Size: 928 Bytes

Versions: 19

Compression:

Stored size: 928 Bytes

Contents

module CouchRest::Model
  module CastedBy
    extend ActiveSupport::Concern
    included do
      self.send(:attr_accessor, :casted_by)
      self.send(:attr_accessor, :casted_by_property)
    end

    # Gets a reference to the actual document in the DB
    # Calls up to the next document if there is one,
    # Otherwise we're at the top and we return self
    def base_doc
      return self if base_doc?
      casted_by ? casted_by.base_doc : nil
    end

    # Checks if we're the top document
    def base_doc?
      !casted_by
    end

    # Provide the property this casted model instance has been
    # used by. If it has not been set, search through the 
    # casted_by objects properties to try and find it.
    #def casted_by_property
    #  return nil unless casted_by
    #  attrs = casted_by.attributes
    #  @casted_by_property ||= casted_by.properties.detect{ |k| attrs[k.to_s] === self }
    #end

  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
couchrest_model-2.2.0.beta2 lib/couchrest/model/casted_by.rb
couchrest_model-2.2.0.beta1 lib/couchrest/model/casted_by.rb
couchrest_model-2.1.0.rc1 lib/couchrest/model/casted_by.rb
couchrest_model-2.1.0.beta2 lib/couchrest/model/casted_by.rb
couchrest_model-2.1.0.beta1 lib/couchrest/model/casted_by.rb
couchrest_model-2.0.4 lib/couchrest/model/casted_by.rb
couchrest_model-2.0.3 lib/couchrest/model/casted_by.rb
couchrest_model-2.0.1 lib/couchrest/model/casted_by.rb
couchrest_model-2.0.0 lib/couchrest/model/casted_by.rb
couchrest_model-2.0.0.beta2 lib/couchrest/model/casted_by.rb
couchrest_model-2.0.0.beta lib/couchrest/model/casted_by.rb
couchrest_model-1.2.0.beta lib/couchrest/model/casted_by.rb
openlogic-couchrest_model-1.0.0 lib/couchrest/model/casted_by.rb
couchrest_model-1.1.2 lib/couchrest/model/casted_by.rb
couchrest_model-1.1.1 lib/couchrest/model/casted_by.rb
couchrest_model-1.1.0 lib/couchrest/model/casted_by.rb
couchrest_model-1.1.0.rc1 lib/couchrest/model/casted_by.rb
couchrest_model-1.1.0.beta5 lib/couchrest/model/casted_by.rb
couchrest_model-1.1.0.beta4 lib/couchrest/model/casted_by.rb