Class: HasHelpers::CacheableItem

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/has_helpers/cacheable_item.rb

Overview

typed: false frozen_string_literal: true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, item = nil, &block) ⇒ CacheableItem

Returns a new instance of CacheableItem.



8
9
10
11
# File 'app/presenters/has_helpers/cacheable_item.rb', line 8

def initialize(key, item = nil, &block)
  self.cache_key = key
  self.promised_item = item || block
end

Instance Attribute Details

#cache_keyObject



22
23
24
25
26
27
# File 'app/presenters/has_helpers/cacheable_item.rb', line 22

def cache_key
  case @cache_key
  when ::ActiveRecord::Base then "#{@cache_key.class.name}/#{@cache_key.id}-#{@cache_key.updated_at.to_i}#{@cache_key['cache_key']}"
  else @cache_key
  end
end

#promised_itemObject

Returns the value of attribute promised_item.



6
7
8
# File 'app/presenters/has_helpers/cacheable_item.rb', line 6

def promised_item
  @promised_item
end

Instance Method Details

#itemObject



13
14
15
16
17
18
19
20
# File 'app/presenters/has_helpers/cacheable_item.rb', line 13

def item
  ::HasHelpers::ItemPresenter.new(
    case promised_item
    when Proc then promised_item[]
    else promised_item
    end
  )
end