Module: CouchRest::Model::Embeddable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Attributes
- Defined in:
- lib/couchrest/model/embeddable.rb
Instance Method Summary collapse
-
#id ⇒ Object
(also: #to_key, #to_param)
The to_param method is needed for rails to generate resourceful routes.
-
#initialize(keys = {}, options = {}) ⇒ Object
Initialize a new Casted Model.
-
#new? ⇒ Boolean
(also: #new_record?)
False if the casted model has already been saved in the containing document.
- #persisted? ⇒ Boolean
-
#update_attributes_without_saving(hash) ⇒ Object
(also: #attributes=)
Sets the attributes from a hash.
Instance Method Details
#id ⇒ Object 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 |
#initialize(keys = {}, options = {}) ⇒ Object
Initialize a new Casted Model. Accepts the same options as CouchRest::Model::Base for preparing and initializing attributes.
31 32 33 34 35 |
# File 'lib/couchrest/model/embeddable.rb', line 31 def initialize(keys = {}, = {}) super() prepare_all_attributes(keys, ) run_callbacks(:initialize) { self } end |
#new? ⇒ Boolean Also known as: new_record?
False if the casted model has already been saved in the containing document
39 40 41 |
# File 'lib/couchrest/model/embeddable.rb', line 39 def new? casted_by.nil? ? true : casted_by.new? end |
#persisted? ⇒ Boolean
44 45 46 |
# File 'lib/couchrest/model/embeddable.rb', line 44 def persisted? !new? end |
#update_attributes_without_saving(hash) ⇒ Object 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 |