Add Style/CollectionMethods to rubocop

This commit is contained in:
Paul Chavard 2019-09-12 11:26:22 +02:00
parent 3f970eee74
commit 3b8d3b7967
37 changed files with 67 additions and 60 deletions

View file

@ -2,19 +2,19 @@ class Champs::CarteChamp < Champ
# We are not using scopes here as we want to access
# the following collections on unsaved records.
def cadastres
geo_areas.select do |area|
geo_areas.filter do |area|
area.source == GeoArea.sources.fetch(:cadastre)
end
end
def quartiers_prioritaires
geo_areas.select do |area|
geo_areas.filter do |area|
area.source == GeoArea.sources.fetch(:quartier_prioritaire)
end
end
def parcelles_agricoles
geo_areas.select do |area|
geo_areas.filter do |area|
area.source == GeoArea.sources.fetch(:parcelle_agricole)
end
end

View file

@ -30,7 +30,7 @@ class Champs::LinkedDropDownListChamp < Champ
end
def to_s
value.present? ? [primary_value, secondary_value].select(&:present?).join(' / ') : ""
value.present? ? [primary_value, secondary_value].filter(&:present?).join(' / ') : ""
end
def for_export

View file

@ -4,6 +4,6 @@ class Champs::PaysChamp < Champs::TextChamp
end
def self.disabled_options
pays.select { |v| (v =~ /^--.*--$/).present? }
pays.filter { |v| (v =~ /^--.*--$/).present? }
end
end

View file

@ -179,7 +179,7 @@ module TagsSubstitutionConcern
raise NameError.new("The class #{self.class.name} includes TagsSubstitutionConcern, it should define the DOSSIER_STATE constant but it does not", :DOSSIER_STATE)
end
tags.select { |tag| tag[:available_for_states].include?(self.class::DOSSIER_STATE) }
tags.filter { |tag| tag[:available_for_states].include?(self.class::DOSSIER_STATE) }
end
def champ_public_tags
@ -213,12 +213,12 @@ module TagsSubstitutionConcern
tags_and_datas
.map { |(tags, data)| [filter_tags(tags), data] }
.inject(text) { |acc, (tags, data)| replace_tags_with_values_from_data(acc, tags, data) }
.reduce(text) { |acc, (tags, data)| replace_tags_with_values_from_data(acc, tags, data) }
end
def replace_tags_with_values_from_data(text, tags, data)
if data.present?
tags.inject(text) do |acc, tag|
tags.reduce(text) do |acc, tag|
replace_tag(acc, tag, data)
end
else

View file

@ -426,15 +426,15 @@ class Dossier < ApplicationRecord
end
def check_mandatory_champs
(champs + champs.select(&:repetition?).flat_map(&:champs))
.select(&:mandatory_and_blank?)
(champs + champs.filter(&:repetition?).flat_map(&:champs))
.filter(&:mandatory_and_blank?)
.map do |champ|
"Le champ #{champ.libelle.truncate(200)} doit être rempli."
end
end
def modifier_annotations!(instructeur)
champs_private.select(&:value_previously_changed?).each do |champ|
champs_private.filter(&:value_previously_changed?).each do |champ|
log_dossier_operation(instructeur, :modifier_annotation, champ)
end
end

View file

@ -9,7 +9,7 @@ class DropDownList < ApplicationRecord
end
def disabled_options
options.select { |v| (v =~ /^--.*--$/).present? }
options.filter { |v| (v =~ /^--.*--$/).present? }
end
def multiple

View file

@ -74,7 +74,7 @@ class Instructeur < ApplicationRecord
active_procedure_overviews = procedures
.publiees
.map { |procedure| procedure.procedure_overview(start_date) }
.select(&:had_some_activities?)
.filter(&:had_some_activities?)
if active_procedure_overviews.count == 0
nil

View file

@ -30,7 +30,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
description: "#{description} (menu primaire)",
lambda: -> (champs) {
champs
.detect { |champ| champ.type_de_champ == tdc }
.find { |champ| champ.type_de_champ == tdc }
&.primary_value
}
}
@ -41,7 +41,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
description: "#{description} (menu secondaire)",
lambda: -> (champs) {
champs
.detect { |champ| champ.type_de_champ == tdc }
.find { |champ| champ.type_de_champ == tdc }
&.secondary_value
}
}

View file

@ -14,7 +14,7 @@ class TypesDeChamp::TypeDeChampBase
libelle: libelle,
description: description,
lambda: -> (champs) {
champs.detect { |champ| champ.type_de_champ == tdc }
champs.find { |champ| champ.type_de_champ == tdc }
}
}
]