Class: ArtirixDataModels::CachedActionAdaptor

Inherits:
Object
  • Object
show all
Defined in:
lib/artirix_data_models/cached_action_adaptor.rb

Direct Known Subclasses

Get, GetFull, GetSome

Defined Under Namespace

Classes: Get, GetFull, GetSome

Constant Summary collapse

STATUS_OK =
'ok'.freeze
STATUS_NOT_FOUND =
'not_found'.freeze
STATUSES =
[STATUS_OK, STATUS_NOT_FOUND]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, cache: nil, **ignored_options) ⇒ CachedActionAdaptor

Returns a new instance of CachedActionAdaptor.



8
9
10
11
12
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 8

def initialize(logger: nil, cache: nil, **ignored_options)
  @logger  = logger || ArtirixDataModels.logger
  @cache   = cache || ArtirixDataModels.cache
  @enabled = true
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



6
7
8
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 6

def cache
  @cache
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 6

def logger
  @logger
end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 14

def cached?
  return false unless enabled?

  cache_exist?
end

#deleteObject



44
45
46
47
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 44

def delete
  return true unless enabled?
  cache_delete
end

#disableObject



36
37
38
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 36

def disable
  @enabled = false
end

#enableObject



32
33
34
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 32

def enable
  @enabled = true
end

#enabled?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 40

def enabled?
  @enabled
end

#fetch(&block) ⇒ Object Also known as: call



20
21
22
23
24
25
26
27
28
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 20

def fetch(&block)
  if cached?
    get_cached_result
  elsif block_given?
    perform &block
  else
    nil
  end
end