Module: CouchRest::CastedModel
- Defined in:
- lib/couchrest/more/casted_model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#base_doc ⇒ Object
Gets a reference to the top level extended document that a model is saved inside of.
- #initialize(keys = {}) ⇒ Object
-
#new? ⇒ Boolean
(also: #new_record?)
False if the casted model has already been saved in the containing document.
-
#update_attributes_without_saving(hash) ⇒ Object
(also: #attributes=)
Sets the attributes from a hash.
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/couchrest/more/casted_model.rb', line 7 def self.included(base) base.send(:include, ::CouchRest::Callbacks) base.send(:include, ::CouchRest::Mixins::Properties) base.send(:attr_accessor, :casted_by) base.send(:attr_accessor, :document_saved) end |
Instance Method Details
#[](key) ⇒ Object
28 29 30 |
# File 'lib/couchrest/more/casted_model.rb', line 28 def [] key super(key.to_s) end |
#[]=(key, value) ⇒ Object
24 25 26 |
# File 'lib/couchrest/more/casted_model.rb', line 24 def []= key, value super(key.to_s, value) end |
#base_doc ⇒ Object
Gets a reference to the top level extended document that a model is saved inside of
34 35 36 37 |
# File 'lib/couchrest/more/casted_model.rb', line 34 def base_doc return nil unless @casted_by @casted_by.base_doc end |
#initialize(keys = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/couchrest/more/casted_model.rb', line 14 def initialize(keys={}) raise StandardError unless self.is_a? Hash apply_defaults # defined in CouchRest::Mixins::Properties super() keys.each do |k,v| self[k.to_s] = v end if keys cast_keys # defined in CouchRest::Mixins::Properties end |
#new? ⇒ Boolean Also known as: new_record?
False if the casted model has already been saved in the containing document
41 42 43 |
# File 'lib/couchrest/more/casted_model.rb', line 41 def new? !@document_saved end |
#update_attributes_without_saving(hash) ⇒ Object Also known as: attributes=
Sets the attributes from a hash
47 48 49 50 51 52 53 54 |
# File 'lib/couchrest/more/casted_model.rb', line 47 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 |