Class: Decidim::FreetextScopes
- Inherits:
-
Rectify::Query
- Object
- Rectify::Query
- Decidim::FreetextScopes
- Defined in:
- app/queries/decidim/freetext_scopes.rb
Overview
This query searches scopes by name.
Class Method Summary collapse
-
.for(organization, lang, text, root = nil) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(organization, lang, text, root = nil) ⇒ FreetextScopes
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, root = nil) ⇒ FreetextScopes
Initializes the class.
organization - an Organization context for the scope search lang - the language code to be used for the search text - the text to be searched in scopes names
21 22 23 24 25 26 |
# File 'app/queries/decidim/freetext_scopes.rb', line 21 def initialize(organization, lang, text, root = nil) @organization = organization @lang = lang @text = text @root = root end |
Class Method Details
.for(organization, lang, text, root = nil) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
organization - an Organization context for the scope search lang - the language code to be used for the search text - the text to be searched in scopes names root - root scope
12 13 14 |
# File 'app/queries/decidim/freetext_scopes.rb', line 12 def self.for(organization, lang, text, root = nil) new(organization, lang, text, root).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.
31 32 33 34 35 36 37 |
# File 'app/queries/decidim/freetext_scopes.rb', line 31 def query if @root @root.descendants.where("name->>? ilike ?", @lang, @text + "%") else @organization.scopes.where("name->>? ilike ?", @lang, @text + "%") end end |