Class: WCC::Contentful::Store::MemoryStore::Query
- Inherits:
-
Object
- Object
- WCC::Contentful::Store::MemoryStore::Query
- Defined in:
- lib/wcc/contentful/store/memory_store.rb
Instance Method Summary collapse
- #apply(filter, context = nil) ⇒ Object
- #eq(field, expected, context = nil) ⇒ Object
-
#initialize(relation) ⇒ Query
constructor
A new instance of Query.
- #result ⇒ Object
Constructor Details
#initialize(relation) ⇒ Query
51 52 53 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 51 def initialize(relation) @relation = relation end |
Instance Method Details
#apply(filter, context = nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 55 def apply(filter, context = nil) return eq(filter[:field], filter[:eq], context) if filter[:eq] raise ArgumentError, "Filter not implemented: #{filter}" end |
#eq(field, expected, context = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 61 def eq(field, expected, context = nil) locale = context[:locale] if context.present? locale ||= 'en-US' Query.new(@relation.select do |v| val = v.dig('fields', field, locale) if val.is_a? Array val.include?(expected) else val == expected end end) end |
#result ⇒ Object
47 48 49 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 47 def result @relation.dup end |