Class: WCC::Contentful::Store::CDNAdapter
- Inherits:
-
Object
- Object
- WCC::Contentful::Store::CDNAdapter
- Defined in:
- lib/wcc/contentful/store/cdn_adapter.rb
Defined Under Namespace
Classes: Query
Instance Attribute Summary collapse
- #client ⇒ Object readonly
Instance Method Summary collapse
- #find(key, hint: nil, **options) ⇒ Object
- #find_all(content_type:, options: nil) ⇒ Object
- #find_by(content_type:, filter: nil, options: nil) ⇒ Object
-
#initialize(client) ⇒ CDNAdapter
constructor
Intentionally not implementing write methods.
Constructor Details
#initialize(client) ⇒ CDNAdapter
Intentionally not implementing write methods
9 10 11 12 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 9 def initialize(client) super() @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
5 6 7 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 5 def client @client end |
Instance Method Details
#find(key, hint: nil, **options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 14 def find(key, hint: nil, **) = { locale: '*' }.merge!( || {}) entry = if hint client.public_send(hint.underscore, key, ) else begin client.entry(key, ) rescue WCC::Contentful::SimpleClient::NotFoundError client.asset(key, ) end end entry&.raw rescue WCC::Contentful::SimpleClient::NotFoundError nil end |
#find_all(content_type:, options: nil) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 38 def find_all(content_type:, options: nil) Query.new( store: self, client: @client, relation: { content_type: content_type }, options: ) end |
#find_by(content_type:, filter: nil, options: nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 31 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!( || {})) q = q.apply(filter) if filter q.first end |