Module: CouchRest::Model::Embeddable

Extended by:
ActiveSupport::Concern
Includes:
Attributes
Defined in:
lib/couchrest/model/embeddable.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) id Also known as: to_key, to_param

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.



50
51
52
53
# File 'lib/couchrest/model/embeddable.rb', line 50

def id
  return nil if base_doc.nil?
  base_doc.id
end

- (Embeddable) initialize(keys = {}, options = {})

Initialize a new Casted Model. Accepts the same options as CouchRest::Model::Base for preparing and initializing attributes.

Returns:



31
32
33
34
35
# File 'lib/couchrest/model/embeddable.rb', line 31

def initialize(keys = {}, options = {})
  super()
  prepare_all_attributes(keys, options)
  run_callbacks(:initialize) { self }
end

- (Boolean) new? Also known as: new_record?

False if the casted model has already been saved in the containing document

Returns:

  • (Boolean)


39
40
41
# File 'lib/couchrest/model/embeddable.rb', line 39

def new?
  casted_by.nil? ? true : casted_by.new?
end

- (Boolean) persisted?

Returns:

  • (Boolean)


44
45
46
# File 'lib/couchrest/model/embeddable.rb', line 44

def persisted?
  !new?
end

- (Object) update_attributes_without_saving(hash) Also known as: attributes=

Sets the attributes from a hash



58
59
60
61
62
63
64
65
# File 'lib/couchrest/model/embeddable.rb', line 58

def update_attributes_without_saving(hash)
  hash.each do |k, v|
    raise NoMethodError, "#{k}= method not available, use property :#{k}" unless self.respond_to?("#{k}=")
  end      
  hash.each do |k, v|
    self.send("#{k}=",v)
  end
end