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

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

Direct Known Subclasses

LazyCacheStore::Query

Constant Summary

Constants inherited from Base::Query

Base::Query::OPERATORS

Instance Method Summary collapse

Methods inherited from Base::Query

#apply

Constructor Details

#initialize(store:, client:, relation:, options: nil, **extra) ⇒ Query

Returns a new instance of Query.

Raises:

  • (ArgumentError)


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
  @options = options || {}
  @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: @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

#resultObject



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

def result
  return response.items unless @options[:include]

  response.items.map { |e| resolve_includes(e, @options[:include]) }
end