Class: WCC::Contentful::Store::Query::Condition
- Inherits:
-
Struct
- Object
- Struct
- WCC::Contentful::Store::Query::Condition
- Defined in:
- lib/wcc/contentful/store/query/condition.rb
Constant Summary collapse
- LINK_KEYS =
rubocop:disable Lint/ConstantDefinitionInBlock
%w[id type linkType].freeze
Instance Attribute Summary collapse
-
#expected ⇒ Object
Returns the value of attribute expected.
-
#locale_fallbacks ⇒ Object
Returns the value of attribute locale_fallbacks.
-
#op ⇒ Object
Returns the value of attribute op.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#each_locale_fallback(&block) ⇒ Object
Starting with the last part of the path that is a locale, iterates all the combinations of potential locale fallbacks.
-
#path_tuples ⇒ Object
Breaks the path into an array of tuples, where each tuple represents an entry subquery.
Instance Attribute Details
#expected ⇒ Object
Returns the value of attribute expected
4 5 6 |
# File 'lib/wcc/contentful/store/query/condition.rb', line 4 def expected @expected end |
#locale_fallbacks ⇒ Object
Returns the value of attribute locale_fallbacks
4 5 6 |
# File 'lib/wcc/contentful/store/query/condition.rb', line 4 def locale_fallbacks @locale_fallbacks end |
#op ⇒ Object
Returns the value of attribute op
4 5 6 |
# File 'lib/wcc/contentful/store/query/condition.rb', line 4 def op @op end |
#path ⇒ Object
Returns the value of attribute path
4 5 6 |
# File 'lib/wcc/contentful/store/query/condition.rb', line 4 def path @path end |
Instance Method Details
#each_locale_fallback(&block) ⇒ Object
Starting with the last part of the path that is a locale, iterates all the combinations of potential locale fallbacks. e.g. if the path is [‘fields’, ‘page’, ‘es-MX’, ‘fields’, ‘title’, ‘es-MX’] then we get:
['fields', 'page', 'es-MX', 'fields', 'title', 'es-MX'] (self)
['fields', 'page', 'es-MX', 'fields', 'title', 'es-US']
['fields', 'page', 'es-MX', 'fields', 'title', 'en-US']
['fields', 'page', 'es-US', 'fields', 'title', 'es-MX']
['fields', 'page', 'es-US', 'fields', 'title', 'es-US']
['fields', 'page', 'es-US', 'fields', 'title', 'en-US']
['fields', 'page', 'en-US', 'fields', 'title', 'es-MX']
['fields', 'page', 'en-US', 'fields', 'title', 'es-US']
['fields', 'page', 'en-US', 'fields', 'title', 'en-US']
57 58 59 60 61 |
# File 'lib/wcc/contentful/store/query/condition.rb', line 57 def each_locale_fallback(&block) return to_enum(:each_locale_fallback) unless block_given? _each_locale_fallback(path_tuples, 0, &block) end |
#path_tuples ⇒ Object
Breaks the path into an array of tuples, where each tuple represents an entry subquery. If the query is a simple query on a field in an entry, there will be one tuple in the array:
{ 'title' => 'foo' } becomes
[['fields', 'title', 'en-US']]
If the query is a query through a link, there will be multiple tuples:
{ 'page' => { 'title' => 'foo' } } becomes
[['fields', 'page', 'en-US'], ['fields', 'title', 'en-US']]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wcc/contentful/store/query/condition.rb', line 19 def path_tuples return @path_tuples if @path_tuples arr = [] remaining = path.dup until remaining.empty? locale = nil link_sys = nil link_field = nil sys_or_fields = remaining.shift field = remaining.shift locale = remaining.shift if sys_or_fields == 'fields' if remaining[0] == 'sys' && LINK_KEYS.include?(remaining[1]) link_sys = remaining.shift link_field = remaining.shift end arr << [sys_or_fields, field, locale, link_sys, link_field].compact end @path_tuples = arr.freeze end |