Module: StrokeDB::Virtualizations

Defined in:
lib/strokedb/document/dsl/virtualize.rb

Instance Method Summary collapse

Instance Method Details

#virtualizes(slotnames, opts = {}) ⇒ Object

Makes a virtual slot. Virtual slot is by all means a regular slot with one exception: it doesn’t get serialized on save. Nevertheless its value is preserved while the document is in memory. You can also set :restore option to false (it is true by default), in such case the slot will be removed before save and not restored. It may be useful for ad hoc slots.

Virtual slots get validated as usual.

User = Meta.new do
  virtualizes :password, :restore => false
  validates_presence_of :crypted_password
end

Regular password is not meant to get serialized in this example, only the crypted one.



20
21
22
23
24
25
# File 'lib/strokedb/document/dsl/virtualize.rb', line 20

def virtualizes(slotnames, opts = {})
  opts = opts.stringify_keys

  slotnames = [slotnames] unless slotnames.is_a?(Array)
  slotnames.each {|slotname| register_virtual(slotname, opts)}
end