Class: Upframework::BaseSearch

Inherits:
BaseService show all
Includes:
ExecuteWrapper
Defined in:
app/searches/upframework/base_search.rb

Defined Under Namespace

Modules: ExecuteWrapper

Constant Summary collapse

DEFAULT_PAGE =
1
DEFAULT_PER_PAGE =
12

Instance Attribute Summary

Attributes inherited from BaseService

#errors

Instance Method Summary collapse

Methods included from ExecuteWrapper

#execute

Methods inherited from BaseService

#error?, #error_messages, #execute, #initialize, #post_initialize, run, #success?

Constructor Details

This class inherits a constructor from Upframework::BaseService

Instance Method Details

#paginate_scopeObject



13
14
15
16
17
18
# File 'app/searches/upframework/base_search.rb', line 13

def paginate_scope
  @model_scope = @model_scope.
    page(@page || DEFAULT_PAGE).
    per(@per_page || DEFAULT_PER_PAGE).
    order(created_at: :desc)
end

#present_value?(field) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/searches/upframework/base_search.rb', line 20

def present_value?(field)
  instance_variable_get("@#{field}").present?
end

#query(field) ⇒ Object



9
10
11
# File 'app/searches/upframework/base_search.rb', line 9

def query(field)
  @model_scope = yield if present_value?(field)
end

#resultObject



5
6
7
# File 'app/searches/upframework/base_search.rb', line 5

def result
  @model_scope
end