Class: Yeti::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/yeti/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, hash) ⇒ Search

Returns a new instance of Search.



8
9
10
11
# File 'lib/yeti/search.rb', line 8

def initialize(context, hash)
  @context = context
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/yeti/search.rb', line 41

def method_missing(method, *args, &block)
  case method.to_s
  when /_id_equals\z/
    search[method].to_i
  when delegate_to_search_pattern
    search[method]
  else
    super
  end
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/yeti/search.rb', line 4

def context
  @context
end

Instance Method Details

#countObject



29
30
31
# File 'lib/yeti/search.rb', line 29

def count
  paginated_results.pagination_record_count
end

#pageObject



17
18
19
# File 'lib/yeti/search.rb', line 17

def page
  @page ||= [1, (hash[:page] || 1).to_i].max
end

#paginated_resultsObject

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/yeti/search.rb', line 52

def paginated_results
  raise NotImplementedError, "#{self.class}#paginated_results"
end

#per_pageObject



21
22
23
24
25
26
27
# File 'lib/yeti/search.rb', line 21

def per_page
  @per_page ||= begin
    per_page = [1, (hash[:per_page] || 20).to_i].max
    max = self.class.max_per_page
    max ? [per_page, max].min : per_page
  end
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/yeti/search.rb', line 37

def respond_to?(method)
  super || method.to_s=~delegate_to_search_pattern
end

#resultsObject



33
34
35
# File 'lib/yeti/search.rb', line 33

def results
  paginated_results.all
end

#searchObject



13
14
15
# File 'lib/yeti/search.rb', line 13

def search
  @search ||= (hash[:search] || {}).with_indifferent_access
end