Class: Decidim::SimilarEmendations
- Includes:
- TranslationsHelper
- Defined in:
- app/queries/decidim/similar_emendations.rb
Overview
Class used to retrieve similar emendations, scoped to the current component.
Class Method Summary collapse
-
.for(amendment) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(amendment) ⇒ SimilarEmendations
constructor
Initializes the class.
-
#query ⇒ Object
Retrieves similar emendations.
Methods included from TranslationsHelper
empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?
Methods included from TranslatableAttributes
Methods inherited from Query
#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|
Constructor Details
#initialize(amendment) ⇒ SimilarEmendations
Initializes the class.
amendment - Decidim::Amendment
18 19 20 21 22 |
# File 'app/queries/decidim/similar_emendations.rb', line 18 def initialize(amendment) @component = amendment.amendable.component @emendation = amendment.emendation @amender = amendment.amender end |
Class Method Details
.for(amendment) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
amendment - Decidim::Amendment
11 12 13 |
# File 'app/queries/decidim/similar_emendations.rb', line 11 def self.for(amendment) new(amendment).query end |
Instance Method Details
#query ⇒ Object
Retrieves similar emendations
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/queries/decidim/similar_emendations.rb', line 25 def query emendation.class .where(component: component) .only_visible_emendations_for(amender, component) .published .not_hidden .where( Arel.sql("GREATEST(#{title_similarity}, #{body_similarity}) >= ?").to_s, translated_attribute(emendation.title), translated_attribute(emendation.body), amendable_module.similarity_threshold ) .limit(amendable_module.similarity_limit) end |