Class: WCC::Contentful::Store::CDNAdapter

Inherits:
Object
  • Object
show all
Includes:
Interface
Defined in:
lib/wcc/contentful/store/cdn_adapter.rb

Defined Under Namespace

Classes: Query

Constant Summary

Constants included from Interface

Interface::INTERFACE_METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = nil, preview: false) ⇒ CDNAdapter

Intentionally not implementing write methods



25
26
27
28
29
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 25

def initialize(client = nil, preview: false)
  super()
  @client = client
  @preview = preview
end

Instance Attribute Details

#clientObject



10
11
12
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 10

def client
  @preview ? @preview_client : @client
end

#preview_client=(value) ⇒ Object (writeonly)

NOTE: CDNAdapter should not instrument store events cause it’s not a store.



8
9
10
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 8

def preview_client=(value)
  @preview_client = value
end

Instance Method Details

#find(key, hint: nil, **options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 31

def find(key, hint: nil, **options)
  options = options&.dup || {}
  entry =
    if hint
      client.public_send(hint.underscore, key, options)
    else
      begin
        client.entry(key, options)
      rescue WCC::Contentful::SimpleClient::NotFoundError
        client.asset(key, options)
      end
    end
  entry&.raw
rescue WCC::Contentful::SimpleClient::NotFoundError
  nil
end

#find_all(content_type:, options: nil) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 55

def find_all(content_type:, options: nil)
  Query.new(
    self,
    client: client,
    relation: { content_type: content_type },
    options: options
  )
end

#find_by(content_type:, filter: nil, options: nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 48

def find_by(content_type:, filter: nil, options: nil)
  # default implementation - can be overridden
  q = find_all(content_type: content_type, options: { limit: 1 }.merge!(options || {}))
  q = q.apply(filter) if filter
  q.first
end

#indexObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 19

def index
  raise NotImplementedError, 'Cannot put data to the CDN!'
end

#index?Boolean

The CDNAdapter cannot index data coming back from the Sync API.

Returns:

  • (Boolean)


15
16
17
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 15

def index?
  false
end