Class: WCC::Contentful::Store::CDNAdapter::Query
- Inherits:
-
Base::Query
- Object
- Base::Query
- WCC::Contentful::Store::CDNAdapter::Query
- Defined in:
- lib/wcc/contentful/store/cdn_adapter.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Base::Query
Instance Method Summary collapse
- #apply_operator(operator, field, expected, context = nil) ⇒ Object
-
#initialize(store:, client:, relation:, options: nil, **extra) ⇒ Query
constructor
A new instance of Query.
- #nested_conditions(field, conditions, context) ⇒ Object
- #result ⇒ Object
Methods inherited from Base::Query
Constructor Details
#initialize(store:, client:, relation:, options: nil, **extra) ⇒ Query
Returns a new instance of Query.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 56 def initialize(store:, client:, relation:, options: nil, **extra) raise ArgumentError, 'Client cannot be nil' unless client.present? raise ArgumentError, 'content_type must be provided' unless relation[:content_type].present? super(store) @client = client @relation = relation = || {} @extra = extra || {} end |
Instance Method Details
#apply_operator(operator, field, expected, context = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 67 def apply_operator(operator, field, expected, context = nil) op = operator == :eq ? nil : operator param = parameter(field, operator: op, context: context, locale: true) self.class.new( store: @store, client: @client, relation: @relation.merge(param => expected), options: , **@extra ) end |
#nested_conditions(field, conditions, context) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 80 def nested_conditions(field, conditions, context) base_param = parameter(field) conditions.reduce(self) do |query, (ref, value)| query.apply({ "#{base_param}.#{parameter(ref)}" => value }, context) end end |
#result ⇒ Object
50 51 52 53 54 |
# File 'lib/wcc/contentful/store/cdn_adapter.rb', line 50 def result return response.items unless [:include] response.items.map { |e| resolve_includes(e, [:include]) } end |