Module: Exegesis::Document::InstanceMethods
- Defined in:
- lib/exegesis/document.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #_attachments=(val) ⇒ 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
69 70 71 |
# File 'lib/exegesis/document.rb', line 69 def == other self.id == other.id end |
#_attachments=(val) ⇒ Object
101 102 103 |
# File 'lib/exegesis/document.rb', line 101 def val @attributes['_attachments'] = val end |
#attachments ⇒ Object
97 98 99 |
# File 'lib/exegesis/document.rb', line 97 def @attachments ||= Exegesis::Document::Attachments.new(self) end |
#id ⇒ Object
73 74 75 |
# File 'lib/exegesis/document.rb', line 73 def id @attributes['_id'] end |
#initialize(hash = {}, db = nil) ⇒ Object
50 51 52 53 |
# File 'lib/exegesis/document.rb', line 50 def initialize hash={}, db=nil super hash @database = db || self.class.database end |
#reload ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/exegesis/document.rb', line 61 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
77 78 79 |
# File 'lib/exegesis/document.rb', line 77 def rev @attributes['_rev'] end |
#save ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/exegesis/document.rb', line 81 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
105 106 107 |
# File 'lib/exegesis/document.rb', line 105 def to_json @attributes.merge({'_attachments' => @attachments}).to_json end |
#update_attributes(attrs = {}) ⇒ Object
91 92 93 94 95 |
# File 'lib/exegesis/document.rb', line 91 def update_attributes attrs={} raise ArgumentError, 'must include a matching _rev attribute' unless (rev || '') == (attrs.delete('_rev') || '') super attrs save end |
#uri ⇒ Object
55 56 57 58 59 |
# File 'lib/exegesis/document.rb', line 55 def uri raise MissingDatabaseError if database.nil? raise NewDocumentError if rev.nil? || id.nil? "#{database.uri}/#{id}" end |