Class: ConvenientService::Support::Cache::Entities::Caches::Array

Inherits:
Base
  • Object
show all
Defined in:
lib/convenient_service/support/cache/entities/caches/array.rb,
lib/convenient_service/support/cache/entities/caches/array/entities/pair.rb

Direct Known Subclasses

ThreadSafeArray

Defined Under Namespace

Modules: Entities

Instance Method Summary collapse

Methods inherited from Base

#==, #[], #[]=, keygen, #keygen, #scope

Methods included from AbstractMethod

abstract_method

Constructor Details

#initialize(array = []) ⇒ void



14
15
16
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 14

def initialize(array = [])
  @array = array
end

Instance Method Details

#clearConvenientService::Support::Cache::Entities::Caches::Array



100
101
102
103
104
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 100

def clear
  array.clear

  self
end

#delete(key) ⇒ Object

Returns Can be any type.

Parameters:

  • key (Object)

    Can be any type.

Returns:

  • (Object)

    Can be any type.



91
92
93
94
95
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 91

def delete(key)
  index = index(key)

  array.delete_at(index).value if index
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 28

def empty?
  array.empty?
end

#exist?(key) ⇒ Boolean

Parameters:

  • key (Object)

    Can be any type.

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 36

def exist?(key)
  index = index(key)

  index ? true : false
end

#fetch(key, &block) ⇒ Object

Returns Can be any type.

Parameters:

  • key (Object)

    Can be any type.

  • block (Proc, nil)

Returns:

  • (Object)

    Can be any type.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 73

def fetch(key, &block)
  index = index(key)

  return array[index].value if index

  return unless block

  value = yield

  array << pair(key, value)

  value
end

#read(key) ⇒ Object

Returns Can be any type.

Parameters:

  • key (Object)

    Can be any type.

Returns:

  • (Object)

    Can be any type.



46
47
48
49
50
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 46

def read(key)
  index = index(key)

  array[index].value if index
end

#storeArray<ConvenientService::Support::Cache::Entities::Caches::Array::Entities::Pair>



21
22
23
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 21

def store
  array
end

#write(key, value) ⇒ Object

Returns Can be any type.

Parameters:

  • key (Object)

    Can be any type.

  • value (Object)

    Can be any type.

Returns:

  • (Object)

    Can be any type.



57
58
59
60
61
62
63
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 57

def write(key, value)
  index = index(key) || array.size

  array[index] = pair(key, value)

  value
end