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



15
16
17
# File 'lib/toqua/search.rb', line 15

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

#default_search_paramsObject



35
36
37
# File 'lib/toqua/search.rb', line 35

def default_search_params
  {}
end

#search_objectObject



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

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



10
11
12
13
# File 'lib/toqua/search.rb', line 10

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

#searching?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/toqua/search.rb', line 31

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