Class: Decidim::Initiatives::FreetextInitiativeTypes
- Inherits:
-
Query
- Object
- Query
- Decidim::Initiatives::FreetextInitiativeTypes
- Defined in:
- app/queries/decidim/initiatives/freetext_initiative_types.rb
Overview
This query searches scopes by name.
Class Method Summary collapse
-
.for(organization, lang, text) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(organization, lang, text) ⇒ FreetextInitiativeTypes
constructor
Initializes the class.
-
#query ⇒ Object
Finds scopes in the given organization and language whose name begins with the indicated text.
Constructor Details
#initialize(organization, lang, text) ⇒ FreetextInitiativeTypes
Initializes the class.
organization - an Organization context for the initiative type search lang - the language code to be used for the search text - the text to be searched in initiative type titles
21 22 23 24 25 |
# File 'app/queries/decidim/initiatives/freetext_initiative_types.rb', line 21 def initialize(organization, lang, text) @organization = organization @lang = lang @text = text end |
Class Method Details
.for(organization, lang, text) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
organization - an Organization context for the initiative type search lang - the language code to be used for the search text - the text to be searched in initiative type titles
12 13 14 |
# File 'app/queries/decidim/initiatives/freetext_initiative_types.rb', line 12 def self.for(organization, lang, text) new(organization, lang, text).query end |
Instance Method Details
#query ⇒ Object
Finds scopes in the given organization and language whose name begins with the indicated text.
Returns an ActiveRecord::Relation.
30 31 32 33 34 35 36 |
# File 'app/queries/decidim/initiatives/freetext_initiative_types.rb', line 30 def query return InitiativesType.where(organization: @organization) if @text.blank? InitiativesType .where(organization: @organization) .where("title->>? ilike ?", @lang, "#{@text}%") end |