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

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

Defined Under Namespace

Classes: Query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CDNAdapter

Returns a new instance of CDNAdapter.



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

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 5

def client
  @client
end

Instance Method Details

#find(key) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 11

def find(key)
  entry =
    begin
      client.entry(key, locale: '*')
    rescue WCC::Contentful::SimpleClient::NotFoundError
      client.asset(key, locale: '*')
    end
  entry&.raw
end

#find_allObject

Raises:

  • (ArgumentError)


21
22
23
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 21

def find_all
  raise ArgumentError, 'use find_by content type instead'
end

#find_by(content_type:) ⇒ Object



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

def find_by(content_type:)
  Query.new(@client, content_type: content_type)
end