Module: Toqua::Search

Extended by:
ActiveSupport::Concern
Includes:
Scoping
Defined in:
lib/toqua/search.rb

Instance Method Summary collapse

Methods included from Scoping

#__run_scope, #apply_scopes

Instance Method Details

#active_search_paramsObject



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

def active_search_params
  search_params.select { |_, b| !b.nil? && b != "" }.to_h
end

#default_search_paramsObject



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

def default_search_params
  {}
end

#search_objectObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/toqua/search.rb', line 21

def search_object
  @search_object ||= begin
    Class.new(RecursiveOpenStruct) do
      extend ActiveModel::Naming

      def self.model_name
        ActiveModel::Name.new(Class, nil, "q")
      end
    end.new(search_params)
  end
end

#search_paramsObject



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

def search_params
  params[:q].permit! if params[:q]
  (params[:q] || {}).to_h.reverse_merge(default_search_params)
end

#searching?Boolean

Returns:

  • (Boolean)


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

def searching?
  params.key?(:q)
end