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
12 13 14 15 16 17 18 19 20 |
# File 'lib/couchbase-orm/persistence.rb', line 12 def create(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| create(attr, &block) } else instance = new(attributes, &block) instance.save instance end end |
#create!(attributes = nil, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/couchbase-orm/persistence.rb', line 22 def create!(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| create!(attr, &block) } else instance = new(attributes, &block) instance.save! instance end end |
#design_document(name = nil) ⇒ Object
Allow classes to overwrite the default document name extend ActiveModel::Naming (included by ActiveModel::Model)
39 40 41 42 |
# File 'lib/couchbase-orm/persistence.rb', line 39 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.
33 34 35 |
# File 'lib/couchbase-orm/persistence.rb', line 33 def fail_validate!(document) raise Error::RecordInvalid.new("Failed to save the record", document) end |
#inherited(child) ⇒ Object
Set a default design document
45 46 47 48 49 50 |
# File 'lib/couchbase-orm/persistence.rb', line 45 def inherited(child) super child.instance_eval do @design_document = child.name.underscore end end |