Class: ArangoDb::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/arangodb-odm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, db_attrs = []) ⇒ Document

Returns a new instance of Document.



19
20
21
# File 'lib/arangodb-odm.rb', line 19

def initialize(collection, db_attrs = [])
  @attributes = {}; @collection = collection; @db_attr_names = db_attrs
end

Instance Attribute Details

#_idObject

Returns the value of attribute _id.



16
17
18
# File 'lib/arangodb-odm.rb', line 16

def _id
  @_id
end

#_revObject

Returns the value of attribute _rev.



16
17
18
# File 'lib/arangodb-odm.rb', line 16

def _rev
  @_rev
end

#attributesObject (readonly)

Returns the value of attribute attributes.



17
18
19
# File 'lib/arangodb-odm.rb', line 17

def attributes
  @attributes
end

#collectionObject

Returns the value of attribute collection.



16
17
18
# File 'lib/arangodb-odm.rb', line 16

def collection
  @collection
end

#db_attrsObject

Returns the value of attribute db_attrs.



16
17
18
# File 'lib/arangodb-odm.rb', line 16

def db_attrs
  @db_attrs
end

#locationObject

Returns the value of attribute location.



16
17
18
# File 'lib/arangodb-odm.rb', line 16

def location
  @location
end

Instance Method Details

#is_new?Boolean

Returns:

  • (Boolean)


23
# File 'lib/arangodb-odm.rb', line 23

def is_new?; self._id.nil?; end

#to_jsonObject



24
25
26
27
28
29
30
31
32
# File 'lib/arangodb-odm.rb', line 24

def to_json
  if @db_attr_names and @db_attr_names.any?
    values = {}
    @db_attr_names.each {|a| values[a] = self.attributes[a.to_s]}
    values.to_json
  else
    self.attributes.to_json
  end
end