Module: Hold::ArrayCell

Includes:
Cell
Included in:
InMemory::ArrayCell, ObjectCell::ArrayPropertyCell, Sequel::QueryArrayCell
Defined in:
lib/hold/interfaces/array_cell.rb

Overview

Interface extending Cell which offers some array-specific persistence methods for use only with Arrays. Default implementations are in terms of get, but it’s expected that you’d override with more efficient implementations.

Defined Under Namespace

Classes: LazyArray

Instance Method Summary collapse

Methods included from Cell

#clear, #empty?, #get_unless_empty, #set_if_empty, #set_unless_empty, #value, #value=

Instance Method Details

#can_get_class?(klass) ⇒ Boolean

Returns:

  • (Boolean)


23
# File 'lib/hold/interfaces/array_cell.rb', line 23

def can_get_class?(klass); klass == Array; end

#can_get_item_class?(klass) ⇒ Boolean

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

Returns:

  • (Boolean)


28
# File 'lib/hold/interfaces/array_cell.rb', line 28

def can_get_item_class?(klass); true; end

#can_set_class?(klass) ⇒ Boolean

Returns:

  • (Boolean)


24
# File 'lib/hold/interfaces/array_cell.rb', line 24

def can_set_class?(klass); klass <= Array; end

#can_set_item_class?(klass) ⇒ Boolean

Returns:

  • (Boolean)


29
# File 'lib/hold/interfaces/array_cell.rb', line 29

def can_set_item_class?(klass); true; end

#get_lazy_arrayObject

returns an instance of ThinModels::LazyArray which lazily computes slices and length based on the get_length and get_slice methods you define.



19
20
21
# File 'lib/hold/interfaces/array_cell.rb', line 19

def get_lazy_array
  LazyArray.new(self)
end

#get_lengthObject



13
14
15
# File 'lib/hold/interfaces/array_cell.rb', line 13

def get_length
  value = get() and value.length
end

#get_slice(start, length) ⇒ Object



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

def get_slice(start, length)
  value = get() and value[start, length]
end