Class: Renderful::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/renderful/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, components:, cache: Cache::Null.new) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/renderful/client.rb', line 7

def initialize(provider:, components:, cache: Cache::Null.new)
  @provider = provider
  @components = components
  @cache = cache
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



5
6
7
# File 'lib/renderful/client.rb', line 5

def cache
  @cache
end

#componentsObject (readonly)

Returns the value of attribute components.



5
6
7
# File 'lib/renderful/client.rb', line 5

def components
  @components
end

#providerObject (readonly)

Returns the value of attribute provider.



5
6
7
# File 'lib/renderful/client.rb', line 5

def provider
  @provider
end

Instance Method Details

#invalidate_cache_from_webhook(body) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/renderful/client.rb', line 26

def invalidate_cache_from_webhook(body)
  result = provider.cache_keys_to_invalidate(body)

  cache.delete(*result[:keys]) if result[:keys].any?

  result[:patterns].each do |pattern|
    cache.delete_matched(pattern)
  end
end

#render(entry_id, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/renderful/client.rb', line 13

def render(entry_id, options = {})
  cache.fetch(ContentEntry.build_cache_key(provider, id: entry_id)) do
    content_entry = provider.find_entry(entry_id)
    component = component_for_entry(content_entry)

    if component.respond_to?(:render_in)
      component.render_in(options.fetch(:view_context))
    else
      component.render
    end
  end
end