Class: ConvenientService::Support::Cache::Entities::Caches::Hash

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

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from AbstractMethod

abstract_method

Constructor Details

#initialize(hash = {}) ⇒ void



12
13
14
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 12

def initialize(hash = {})
  @hash = hash
end

Instance Method Details

#clearConvenientService::Support::Cache::Entities::Caches::Hash



95
96
97
98
99
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 95

def clear
  hash.clear

  self
end

#delete(key) ⇒ Object

Returns Can be any type.

Parameters:

  • key (Object)

    Can be any type.

Returns:

  • (Object)

    Can be any type.



88
89
90
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 88

def delete(key)
  hash.delete(key)
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  hash.empty?
end

#exist?(key) ⇒ Boolean

Parameters:

  • key (Object)

    Can be any type.

Returns:

  • (Boolean)


40
41
42
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 40

def exist?(key)
  hash.has_key?(key)
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.



75
76
77
78
79
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 75

def fetch(key, &block)
  return hash[key] unless block

  hash.fetch(key) { hash[key] = yield }
end

#read(key) ⇒ Object

Returns Can be any type.

Parameters:

  • key (Object)

    Can be any type.

Returns:

  • (Object)

    Can be any type.



51
52
53
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 51

def read(key)
  hash[key]
end

#storeHash{Object => Object}

Returns:

  • (Hash{Object => Object})


19
20
21
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 19

def store
  hash
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.



63
64
65
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 63

def write(key, value)
  hash[key] = value
end