Module: Store

Defined in:
lib/source/redshift/store.rb

Overview

Classes mixing in Store gain the ability to store properties related to DOM objects without causing memory-sapping circular references.

Instance Method Summary collapse

Instance Method Details

#delete(property) ⇒ Object

call-seq:

obj.delete(sym) -> obj

Deletes the property sym, then returns obj.



13
14
15
16
17
18
19
20
21
# File 'lib/source/redshift/store.rb', line 13

def delete(property)
  `var stringId=''+this.__id__`
  storage = `#{Store}.__table__[stringId]`
  storage = `#{Store}.__table__[stringId]=#{{}}` unless storage
  value = storage[property]
  value = nil if `value==null`
  `delete storage.__contents__[property.m$hash()]`
  return value
end

#fetch(property, deflt = nil) ⇒ Object

call-seq:

obj.retrieve(sym, default = nil) -> object or default

Returns the property sym, or default if the property is not defined.



28
29
30
31
32
33
34
35
# File 'lib/source/redshift/store.rb', line 28

def fetch(property, deflt = nil)
  `var stringId=''+this.__id__`
  storage = `#{Store}.__table__[stringId]`
  storage = `#{Store}.__table__[stringId]=#{{}}` unless storage
  value   = storage[property.to_sym]
  value   = storage[property.to_sym] = deflt unless `$T(value)||value==false`
  return value
end

#store(hash) ⇒ Object

call-seq:

obj.store(hash) -> object

Stores the key-value pairs as properties of obj, then returns obj.



42
43
44
45
46
47
# File 'lib/source/redshift/store.rb', line 42

def store(hash)
  `var stringId=''+this.__id__`
  storage = `#{Store}.__table__[stringId]`
  storage = `#{Store}.__table__[stringId]=#{{}}` unless storage
  hash.each {|property,value| storage[property.to_sym] = value }
end