Class: GraphQL::Searchkick::LazySearch
- Inherits:
-
Object
- Object
- GraphQL::Searchkick::LazySearch
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/graphql/searchkick/lazy_search.rb
Constant Summary collapse
- SEARCH_ALL =
'*'.freeze
Instance Attribute Summary collapse
-
#limit_value ⇒ Object
Returns the value of attribute limit_value.
-
#model_class ⇒ Object
Returns the value of attribute model_class.
-
#offset_value ⇒ Object
Returns the value of attribute offset_value.
-
#options ⇒ Object
Returns the value of attribute options.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(options, query:, model_class:) ⇒ LazySearch
constructor
A new instance of LazySearch.
- #limit(value) ⇒ Object
- #limit!(value) ⇒ Object
- #load ⇒ Object
- #offset(value) ⇒ Object
- #offset!(value) ⇒ Object
Constructor Details
#initialize(options, query:, model_class:) ⇒ LazySearch
Returns a new instance of LazySearch.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 20 def initialize(, query:, model_class:) @query = if query.nil? || query.empty? SEARCH_ALL else query end @model_class = model_class @options = || {} if @options.key?(:limit) self.limit_value = @options[:limit] end end |
Instance Attribute Details
#limit_value ⇒ Object
Returns the value of attribute limit_value.
13 14 15 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 13 def limit_value @limit_value end |
#model_class ⇒ Object
Returns the value of attribute model_class.
13 14 15 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 13 def model_class @model_class end |
#offset_value ⇒ Object
Returns the value of attribute offset_value.
13 14 15 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 13 def offset_value @offset_value end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 13 def @options end |
#query ⇒ Object
Returns the value of attribute query.
13 14 15 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 13 def query @query end |
Instance Method Details
#limit(value) ⇒ Object
43 44 45 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 43 def limit(value) clone.limit!(value) end |
#limit!(value) ⇒ Object
51 52 53 54 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 51 def limit!(value) self.limit_value = value self end |
#load ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 35 def load return @result if defined? @result @result = model_class.search(query, **.merge(limit: limit_value, offset: offset_value)) @result end |
#offset(value) ⇒ Object
47 48 49 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 47 def offset(value) clone.offset!(value) end |
#offset!(value) ⇒ Object
56 57 58 59 |
# File 'lib/graphql/searchkick/lazy_search.rb', line 56 def offset!(value) self.offset_value = value self end |