Class: WingedCouch::Abstract::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/winged_couch/abstract/document.rb

Overview

Class which represents abstract document.

It implements base logic for document class.

Direct Known Subclasses

Native::Document

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database, data = {}) ⇒ Document

Returns a new instance of Document


16
17
18
19
# File 'lib/winged_couch/abstract/document.rb', line 16

def initialize(database, data = {})
  @database = database
  @data = data.with_indifferent_access
end

Instance Attribute Details

#dataObject

Returns the value of attribute data


14
15
16
# File 'lib/winged_couch/abstract/document.rb', line 14

def data
  @data
end

#databaseObject

Returns the value of attribute database


13
14
15
# File 'lib/winged_couch/abstract/document.rb', line 13

def database
  @database
end

Instance Method Details

#==(other_object) ⇒ Object

Returns true if other_object is an object of same class,

stored in the same database and has same +_id+ and +_rev+

Parameters:

  • other_object (Object)

    obejct to compare


66
67
68
69
70
71
# File 'lib/winged_couch/abstract/document.rb', line 66

def ==(other_object)
  other_object.instance_of?(self.class) &&
    database.present? && other_object.database == self.database &&
    _id.present?      && other_object._id      == self._id      &&
    _rev.present?     && other_object._rev     == self._rev
end

#_idString

Returns document id

Returns:

  • (String)

33
34
35
# File 'lib/winged_couch/abstract/document.rb', line 33

def _id
  data[:_id]
end

#_id=(new_id) ⇒ Object

Sets document id

Parameters:

  • new_id (String)

    new document id


49
50
51
# File 'lib/winged_couch/abstract/document.rb', line 49

def _id=(new_id)
  data[:_id] = new_id
end

#_revString

Returns document revision

Returns:

  • (String)

41
42
43
# File 'lib/winged_couch/abstract/document.rb', line 41

def _rev
  data[:_rev]
end

#_rev=(new_rev) ⇒ Object

Sets document revision

Parameters:

  • new_rev (String)

    new document revision


57
58
59
# File 'lib/winged_couch/abstract/document.rb', line 57

def _rev=(new_rev)
  data[:_rev] = new_rev
end

#inspectString

Returns the contents of the document as a nicely formatted string.

Returns:

  • (String)

25
26
27
# File 'lib/winged_couch/abstract/document.rb', line 25

def inspect
  "#<#{self.class.name} data=#{data.inspect}>"
end