| 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'
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.
# 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
Get the named attribute.
# File lib/rddb/document.rb, line 29
29: def [](name)
30: @data[name.to_sym]
31: end
Set the named attribute.
# 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
# File lib/rddb/document.rb, line 39
39: def attribute?(name)
40: @data.key?(name)
41: end