Class: GraphQL::Searchkick::LazySearch

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/graphql/searchkick/lazy_search.rb

Constant Summary collapse

SEARCH_ALL =
'*'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options, query:, model_class:)
  @query =
    if query.nil? || query.empty?
      SEARCH_ALL
    else
      query
    end
  @model_class = model_class
  @options = options || {}

  if @options.key?(:limit)
    self.limit_value = @options[:limit]
  end
end

Instance Attribute Details

#limit_valueObject

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_classObject

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_valueObject

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

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/graphql/searchkick/lazy_search.rb', line 13

def options
  @options
end

#queryObject

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

#loadObject



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, **options.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