Class Rddb::Document
In: lib/rddb/document.rb
Parent: Object

A document, which is essentially a map of name/value pairs. You can access attributes directly through [] and []=. You may also access attributes for reading by calling a method with the attribute name. For example:

  doc = Document.new(:name => 'Bob')
  doc[:name]
  => 'Bob'
  doc.name
  => 'Bob'

Methods

[]   []=   attribute?   id   new   to_wire  

Public Class methods

Construct a document. You may pass a Hash to prefill the document attributes. The :id attribute is a special attribute that is used as a unique identifier for storage purposes - if you do not specify a value for :id then a UUID key will be generated.

[Source]

    # File lib/rddb/document.rb, line 17
17:     def initialize(data={})
18:       @data = data.to_sym_key_hash
19:       @data[:id] ||= UUID.new
20:       # undef_method :type
21:     end

Public Instance methods

Get the named attribute.

[Source]

    # File lib/rddb/document.rb, line 29
29:     def [](name)
30:       @data[name.to_sym]
31:     end

Set the named attribute.

[Source]

    # File lib/rddb/document.rb, line 34
34:     def []=(name, value)
35:       @data[name.to_sym] = value
36:     end

Returns true if the document has the named attribute

[Source]

    # File lib/rddb/document.rb, line 39
39:     def attribute?(name)
40:       @data.key?(name)
41:     end

Return the Document ID.

[Source]

    # File lib/rddb/document.rb, line 24
24:     def id
25:       @data[:id]
26:     end

Create a representation of the document suitable for sending over HTTP.

[Source]

    # File lib/rddb/document.rb, line 63
63:     def to_wire
64:       pairs = []
65:       @data.each do |name,value|
66:         pairs << "#{CGI.escape(name.to_s)}=#{CGI.escape(value)}"
67:       end
68:       pairs.join('&')
69:     end

[Validate]