Class: WCC::Contentful::Middleware::Store::DelegatingQuery
- Inherits:
-
Object
- Object
- WCC::Contentful::Middleware::Store::DelegatingQuery
- Includes:
- Enumerable, Store::Query::Interface
- Defined in:
- lib/wcc/contentful/middleware/store.rb
Constant Summary
Constants included from Store::Query::Interface
Store::Query::Interface::OPERATORS
Instance Attribute Summary collapse
-
#middleware ⇒ Object
readonly
Returns the value of attribute middleware.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#wrapped_query ⇒ Object
readonly
Returns the value of attribute wrapped_query.
Instance Method Summary collapse
- #apply(filter, context = nil) ⇒ Object
- #apply_operator(operator, field, expected, context = nil) ⇒ Object
- #count ⇒ Object
-
#initialize(wrapped_query, middleware:, options: nil, **extra) ⇒ DelegatingQuery
constructor
A new instance of DelegatingQuery.
- #to_enum ⇒ Object
Methods included from Store::Query::Interface
Constructor Details
#initialize(wrapped_query, middleware:, options: nil, **extra) ⇒ DelegatingQuery
Returns a new instance of DelegatingQuery.
154 155 156 157 158 159 |
# File 'lib/wcc/contentful/middleware/store.rb', line 154 def initialize(wrapped_query, middleware:, options: nil, **extra) @wrapped_query = wrapped_query @middleware = middleware @options = || {} @extra = extra end |
Instance Attribute Details
#middleware ⇒ Object (readonly)
Returns the value of attribute middleware.
111 112 113 |
# File 'lib/wcc/contentful/middleware/store.rb', line 111 def middleware @middleware end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
111 112 113 |
# File 'lib/wcc/contentful/middleware/store.rb', line 111 def @options end |
#wrapped_query ⇒ Object (readonly)
Returns the value of attribute wrapped_query.
111 112 113 |
# File 'lib/wcc/contentful/middleware/store.rb', line 111 def wrapped_query @wrapped_query end |
Instance Method Details
#apply(filter, context = nil) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/wcc/contentful/middleware/store.rb', line 124 def apply(filter, context = nil) self.class.new( wrapped_query.apply(filter, context), middleware: middleware, options: , **@extra ) end |
#apply_operator(operator, field, expected, context = nil) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/wcc/contentful/middleware/store.rb', line 133 def apply_operator(operator, field, expected, context = nil) self.class.new( wrapped_query.apply_operator(operator, field, expected, context), middleware: middleware, options: , **@extra ) end |
#count ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/wcc/contentful/middleware/store.rb', line 99 def count if middleware.has_select? raise NameError, "Count cannot be determined because the middleware '#{middleware}' " \ "implements the #select? method. Please use '.to_a.count' to count entries that " \ 'pass the #select? method.' end # The wrapped query may get count from the "Total" field in the response, # or apply a "COUNT(*)" to the query. wrapped_query.count end |
#to_enum ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/wcc/contentful/middleware/store.rb', line 113 def to_enum result = wrapped_query.to_enum result = result.select { |x| middleware.select?(x, ) } if middleware.has_select? if && [:include] result = result.map { |x| middleware.resolve_includes(x, [:include], ) } end result.map { |x| middleware.transform(x, ) } end |