Module: CouchbaseOrm::Persistence::ClassMethods
- Defined in:
- lib/couchbase-orm/persistence.rb
Instance Method Summary collapse
- #create(attributes = nil, &block) ⇒ Object
- #create!(attributes = nil, &block) ⇒ Object
-
#design_document(name = nil) ⇒ Object
Allow classes to overwrite the default document name extend ActiveModel::Naming (included by ActiveModel::Model).
-
#fail_validate!(document) ⇒ Object
Raise an error if validation failed.
-
#inherited(child) ⇒ Object
Set a default design document.
Instance Method Details
#create(attributes = nil, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/couchbase-orm/persistence.rb', line 19 def create(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| create(attr, &block) } else instance = new(attributes, &block) instance.save instance.reset_object! instance end end |
#create!(attributes = nil, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/couchbase-orm/persistence.rb', line 30 def create!(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| create!(attr, &block) } else instance = new(attributes, &block) instance.save! instance.reset_object! instance end end |
#design_document(name = nil) ⇒ Object
Allow classes to overwrite the default document name extend ActiveModel::Naming (included by ActiveModel::Model)
48 49 50 51 |
# File 'lib/couchbase-orm/persistence.rb', line 48 def design_document(name = nil) return @design_document unless name @design_document = name.to_s end |
#fail_validate!(document) ⇒ Object
Raise an error if validation failed.
42 43 44 |
# File 'lib/couchbase-orm/persistence.rb', line 42 def fail_validate!(document) raise Error::RecordInvalid.new("Failed to save the record", document) end |
#inherited(child) ⇒ Object
Set a default design document
54 55 56 57 58 59 |
# File 'lib/couchbase-orm/persistence.rb', line 54 def inherited(child) super child.instance_eval do @design_document = child.name.underscore end end |