lib/wcc/contentful/store/cdn_adapter.rb in wcc-contentful-1.3.2 vs lib/wcc/contentful/store/cdn_adapter.rb in wcc-contentful-1.4.0.rc1

- old
+ new

@@ -27,11 +27,11 @@ @client = client @preview = preview end def find(key, hint: nil, **options) - options = { locale: '*' }.merge!(options || {}) + options = options&.dup || {} entry = if hint client.public_send(hint.underscore, key, options) else begin @@ -112,11 +112,11 @@ if expected.is_a?(Array) expected = expected.join(',') op = :in if op.nil? end - param = parameter(field, operator: op, context: context, locale: true) + param = parameter(field, operator: op, context: context, locale: false) self.class.new( @store, client: @client, relation: @relation.merge(param => expected), @@ -155,14 +155,14 @@ def response @response ||= if @relation[:content_type] == 'Asset' @client.assets( - { locale: '*' }.merge!(@relation.reject { |k| k == :content_type }).merge!(@options) + @relation.reject { |k| k == :content_type }.merge(@options) ) else - @client.entries({ locale: '*' }.merge!(@relation).merge!(@options)) + @client.entries(@relation.merge(@options)) end end def resolve_includes(entry, includes, depth:) return entry unless entry && depth && depth > 0 @@ -178,9 +178,18 @@ return val unless included = includes[val.dig('sys', 'id')] included end + # Constructs the CDN query parameter from a structured field definition and + # operator. + # Notes: + # * "eq" can be omitted, e.g. 'fields.slug=/' is equivalent to 'fields.slug[eq]=/' + # * If "locale" is specified in the query, matching is done against that locale, + # unless the query explicitly specifies the locale. Examples: + # 'locale=es-US&fields.title=página principal' matches on the es locale + # 'locale=en-US&fields.title=página principal' returns nothing + # 'locale=en-US&fields.title.es-US=página principal' returns the page, but in the english locale. def parameter(field, operator: nil, context: nil, locale: false) if sys?(field) "#{field}#{op_param(operator)}" elsif id?(field) "sys.#{field}#{op_param(operator)}"