Class: ConvenientService::Support::Cache::Entities::Caches::Array
- 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
Defined Under Namespace
Modules: Entities
Instance Method Summary collapse
- #clear ⇒ ConvenientService::Support::Cache::Entities::Caches::Array
-
#delete(key) ⇒ Object
Can be any type.
- #empty? ⇒ Boolean
- #exist?(key) ⇒ Boolean
-
#fetch(key, &block) ⇒ Object
Can be any type.
- #initialize(array = []) ⇒ void constructor
-
#read(key) ⇒ Object
Can be any type.
- #store ⇒ Array<ConvenientService::Support::Cache::Entities::Caches::Array::Entities::Pair>
-
#write(key, value) ⇒ Object
Can be any type.
Methods inherited from Base
#==, #[], #[]=, #keygen, keygen, #scope
Methods included from ConvenientService::Support::Concern
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
#clear ⇒ ConvenientService::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.
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
28 29 30 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 28 def empty? array.empty? end |
#exist?(key) ⇒ 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.
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.
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 |
#store ⇒ Array<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.
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 |