Module: Hold::Cell

Included in:
ArrayCell, HashRepository::KeyCell, InMemory::Cell, ObjectCell, ObjectCell::PropertyCell
Defined in:
lib/hold/interfaces/cell.rb

Overview

The most fundamental persistence interface. Just offers a storage slot which stores a single instance, supporting get/set

Instance Method Summary collapse

Instance Method Details

#can_get_class?(_class) ⇒ Boolean

Can override to indicate if you only support getting/setting a particular class or classes:

Returns:

  • (Boolean)


53
54
55
# File 'lib/hold/interfaces/cell.rb', line 53

def can_get_class?(_class)
  true
end

#can_set_class?(_class) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/hold/interfaces/cell.rb', line 57

def can_set_class?(_class)
  true
end

#clearObject



31
32
33
# File 'lib/hold/interfaces/cell.rb', line 31

def clear
  raise UnsupportedOperation
end

#empty?Boolean

Cells may optionally be ‘emptyable?’, that is, admit a special state of ‘empty’ which is different to the state of storing an instance.

empty and nil are distinct states.

empty: undefined / uninitialized / unknown / not persisted / key not present in hash / missing nil: null / known to be nil / persisted explicitly as being nil / key present in hash with value of nil

Annoying as this may seem this is useful in a bunch of contexts with the data models we’re constrained to be using. Eg “row exists but value of column is NULL” vs “row doesn’t exist” in SQL, or “property missing” vs “property present and equal to null” for JSON objects

Returns:

  • (Boolean)


27
28
29
# File 'lib/hold/interfaces/cell.rb', line 27

def empty?
  false
end

#get_unless_emptyObject Also known as: get!

Raises:



45
46
47
48
# File 'lib/hold/interfaces/cell.rb', line 45

def get_unless_empty
  raise EmptyConflict if empty?
  get
end

#set_if_empty(value) ⇒ Object

Raises:



35
36
37
38
# File 'lib/hold/interfaces/cell.rb', line 35

def set_if_empty(value)
  raise EmptyConflict unless empty?
  set(value)
end

#set_unless_empty(value) ⇒ Object

Raises:



40
41
42
43
# File 'lib/hold/interfaces/cell.rb', line 40

def set_unless_empty(value)
  raise EmptyConflict if empty?
  set(value)
end

#valueObject



5
6
7
# File 'lib/hold/interfaces/cell.rb', line 5

def value
  raise UnsupportedOperation
end

#value=(value) ⇒ Object



9
10
11
# File 'lib/hold/interfaces/cell.rb', line 9

def value=(value)
  raise UnsupportedOperation
end