Class: LooseChange::Base
- Inherits:
-
Object
- Object
- LooseChange::Base
- Extended by:
- ActiveModel::Callbacks, Attachments, Attributes, Helpers, Naming, Pagination, Persistence, Spatial, Validations, Views
- Includes:
- ActiveModel::AttributeMethods, ActiveModel::Dirty, ActiveModel::Serialization, ActiveModel::Serializers::JSON, ActiveModel::Validations, AttachmentClassMethods, AttributeClassMethods, Errors, Helpers, NamingClassMethods, PersistenceClassMethods
- Defined in:
- lib/loose_change/base.rb
Constant Summary
Constants included from Spatial
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns the value of attribute attachments.
Attributes included from PersistenceClassMethods
#_attachments, #_id, #_rev, #database, #destroyed, #id, #new_record
Attributes included from Errors
Instance Method Summary collapse
- #==(other_model) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(args = {}) ⇒ Base
constructor
A new instance of Base.
- #to_key ⇒ Object
- #to_model ⇒ Object
- #to_param ⇒ Object
Methods included from Attributes
default, property, timestamps!
Methods included from Persistence
create, create!, find, instantiate_from_hash, use_database
Methods included from Views
add_view, all, doc_key, existence_check, key_for, view, view_by, view_by_all
Methods included from Validations
Methods included from Pagination
paginate, paginated_by, paginated_view_by
Methods included from Spatial
Methods included from Helpers
default_headers, design_document_uri
Methods included from PersistenceClassMethods
#destroy, #destroyed?, #new_record?, #persisted?, #save, #save!
Methods included from NamingClassMethods
Methods included from AttachmentClassMethods
#attach, #attachment, #put_attachment, #retrieve_attachment
Methods included from AttributeClassMethods
#attributes, #update_attribute, #update_attributes
Constructor Details
#initialize(args = {}) ⇒ Base
Returns a new instance of Base.
61 62 63 64 65 66 67 68 |
# File 'lib/loose_change/base.rb', line 61 def initialize(args = {}) @errors = ActiveModel::Errors.new(self) @database = self.database @new_record = true unless args['_id'] args.each {|property, value| self.send("#{property}=".to_sym, value)} apply_defaults self end |
Instance Attribute Details
#attachments ⇒ Object
Returns the value of attribute attachments.
34 35 36 |
# File 'lib/loose_change/base.rb', line 34 def @attachments end |
Instance Method Details
#==(other_model) ⇒ Object Also known as: eql?
48 49 50 51 52 53 |
# File 'lib/loose_change/base.rb', line 48 def ==(other_model) return false unless other_model && other_model.is_a?(self.class) id == other_model.id && _rev == other_model._rev && !(changed? || other_model.changed?) end |
#hash ⇒ Object
57 58 59 |
# File 'lib/loose_change/base.rb', line 57 def hash id.try(:hex) || super end |
#to_key ⇒ Object
36 37 38 |
# File 'lib/loose_change/base.rb', line 36 def to_key persisted? ? [id] : nil end |
#to_model ⇒ Object
40 41 42 |
# File 'lib/loose_change/base.rb', line 40 def to_model self end |
#to_param ⇒ Object
44 45 46 |
# File 'lib/loose_change/base.rb', line 44 def to_param (to_key && persisted?) ? to_key.join('-') : nil end |