Module: CouchTomato::Persistence

Includes:
Base
Defined in:
lib/couch_tomato/persistence.rb,
lib/couch_tomato/persistence/base.rb,
lib/couch_tomato/persistence/json.rb,
lib/couch_tomato/persistence/callbacks.rb,
lib/couch_tomato/persistence/properties.rb,
lib/couch_tomato/persistence/validation.rb,
lib/couch_tomato/persistence/simple_property.rb,
lib/couch_tomato/persistence/dirty_attributes.rb,
lib/couch_tomato/persistence/magic_timestamps.rb,
lib/couch_tomato/persistence/belongs_to_property.rb

Defined Under Namespace

Modules: Base, Callbacks, DirtyAttributes, Json, MagicTimestamps, Nested, Properties, Validation Classes: BelongsToProperty, SimpleProperty

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#==, #attributes, #attributes=, #initialize

Class Method Details

.included(base) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/couch_tomato/persistence.rb', line 59

def self.included(base)
  base.send :include, Properties, Callbacks, Validation, Json#, CouchTomato::View::CustomViews
  # base.send :include, DirtyAttributes
  base.send :include, MagicTimestamps
  base.class_eval do
    attr_accessor :_id, :_rev, :_attachments, :_deleted
    attr_accessor :metadata
    alias_method :id, :_id
  end
end

Instance Method Details

#new?Boolean Also known as: new_record?

returns true if a model hasn’t been saved yet, false otherwise

Returns:

  • (Boolean)


71
72
73
# File 'lib/couch_tomato/persistence.rb', line 71

def new?
  _rev.nil?
end

#to_paramObject

returns the document id this is used by rails to construct URLs can be overridden to for example use slugs for URLs instead if ids



79
80
81
# File 'lib/couch_tomato/persistence.rb', line 79

def to_param
  _id
end