Module: Exegesis::Document::InstanceMethods
- Defined in:
- lib/exegesis/document.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attachments ⇒ Object
- #id ⇒ Object
- #initialize(hash = {}, db = nil) ⇒ Object
- #reload ⇒ Object
- #rev ⇒ Object
- #save ⇒ Object
- #to_json ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
- #uri ⇒ Object
Instance Method Details
#==(other) ⇒ Object
57 58 59 |
# File 'lib/exegesis/document.rb', line 57 def == other self.id == other.id end |
#attachments ⇒ Object
85 86 87 |
# File 'lib/exegesis/document.rb', line 85 def @attachments ||= Exegesis::Document::Attachments.new(self) end |
#id ⇒ Object
61 62 63 |
# File 'lib/exegesis/document.rb', line 61 def id @attributes['_id'] end |
#initialize(hash = {}, db = nil) ⇒ Object
38 39 40 41 |
# File 'lib/exegesis/document.rb', line 38 def initialize hash={}, db=nil super hash @database = db end |
#reload ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/exegesis/document.rb', line 49 def reload raise NewDocumentError if rev.nil? || id.nil? raise MissingDatabaseError if database.nil? @attachments = nil @references = nil @attributes = database.raw_get(id) end |
#rev ⇒ Object
65 66 67 |
# File 'lib/exegesis/document.rb', line 65 def rev @attributes['_rev'] end |
#save ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/exegesis/document.rb', line 69 def save if respond_to?(:set_timestamps) if self.class.unique_id && id.nil? save_with_custom_unique_id else save_document end @attachments.clean! if @attachments && @attachments.dirty? end |
#to_json ⇒ Object
89 90 91 |
# File 'lib/exegesis/document.rb', line 89 def to_json @attributes.merge({'_attachments' => @attachments}).to_json end |
#update_attributes(attrs = {}) ⇒ Object
79 80 81 82 83 |
# File 'lib/exegesis/document.rb', line 79 def update_attributes attrs={} raise ArgumentError, 'must include a matching _rev attribute' unless (rev || '') == (attrs.delete('_rev') || '') super attrs save end |
#uri ⇒ Object
43 44 45 46 47 |
# File 'lib/exegesis/document.rb', line 43 def uri raise MissingDatabaseError if database.nil? raise NewDocumentError if rev.nil? || id.nil? "#{database.uri}/#{id}" end |