Sha256: 3111d11cd60746d1c943493bdba23cf5f09fe979624e8211b416f03d13aa7b7e

Contents?: true

Size: 1.22 KB

Versions: 32

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Decidim
  # This query searches scopes by name.
  class FreetextScopes < Rectify::Query
    # 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
    def self.for(organization, lang, text, root = nil)
      new(organization, lang, text, root).query
    end

    # 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
    def initialize(organization, lang, text, root = nil)
      @organization = organization
      @lang = lang
      @text = text
      @root = root
    end

    # Finds scopes in the given organization and language whose name begins with the indicated text.
    #
    # Returns an ActiveRecord::Relation.
    def query
      if @root
        @root.descendants.where("name->>? ilike ?", @lang, @text + "%")
      else
        @organization.scopes.where("name->>? ilike ?", @lang, @text + "%")
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
decidim-core-0.6.3 app/queries/decidim/freetext_scopes.rb
decidim-0.6.3 decidim-core/app/queries/decidim/freetext_scopes.rb
decidim-core-0.6.2 app/queries/decidim/freetext_scopes.rb
decidim-0.6.2 decidim-core/app/queries/decidim/freetext_scopes.rb
decidim-core-0.6.1 app/queries/decidim/freetext_scopes.rb
decidim-0.6.1 decidim-core/app/queries/decidim/freetext_scopes.rb
decidim-core-0.6.0 app/queries/decidim/freetext_scopes.rb
decidim-0.6.0 decidim-core/app/queries/decidim/freetext_scopes.rb
decidim-core-0.5.1 app/queries/decidim/freetext_scopes.rb
decidim-0.5.1 decidim-core/app/queries/decidim/freetext_scopes.rb
decidim-core-0.5.0 app/queries/decidim/freetext_scopes.rb
decidim-0.5.0 decidim-core/app/queries/decidim/freetext_scopes.rb