Class: Decidim::ResourceSearch

Inherits:
Ransack::Search
  • Object
show all
Defined in:
app/services/decidim/resource_search.rb

Overview

This is the base class to be used by other search services. This helps the searches to work with context attributes that are not passed from the user interface.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, params = {}, options = {}) ⇒ ResourceSearch

Returns a new instance of ResourceSearch.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/decidim/resource_search.rb', line 10

def initialize(object, params = {}, options = {})
  @user = options[:current_user] || options[:user]
  @component = options[:component]
  @organization = options[:organization] || component&.organization
  @search_context = options[:search_context] || :participants
  configure(options)

  # The super method calls the build method in the super class, which can be
  # overridden by the individual search implementations, so call this as the
  # last thing at the initialize method. The params are passed to the
  # build method as the only argument.
  super
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



8
9
10
# File 'app/services/decidim/resource_search.rb', line 8

def component
  @component
end

#organizationObject (readonly)

Returns the value of attribute organization.



8
9
10
# File 'app/services/decidim/resource_search.rb', line 8

def organization
  @organization
end

#search_contextObject (readonly)

Returns the value of attribute search_context.



8
9
10
# File 'app/services/decidim/resource_search.rb', line 8

def search_context
  @search_context
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'app/services/decidim/resource_search.rb', line 8

def user
  @user
end

Instance Method Details

#configure(options) ⇒ Object



24
25
26
27
28
# File 'app/services/decidim/resource_search.rb', line 24

def configure(options)
  # This can be overridden by the search implementations in order to set
  # extra variables based on the options passed to the search class before
  # calling the build method below.
end