From 956048ffead73b437dde88b88f9cca5d86e01f27 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 15 Sep 2023 09:50:29 +0200 Subject: [PATCH] refactor(type de champ): extract routable? method --- app/models/procedure_revision.rb | 2 +- app/models/type_de_champ.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 4ce0a65ec..2369087f7 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -224,7 +224,7 @@ class ProcedureRevision < ApplicationRecord end def routable_types_de_champ - types_de_champ_public.filter { |tdc| [:drop_down_list, :departements, :regions, :communes].include?(tdc.type_champ.to_sym) } + types_de_champ_public.filter(&:routable?) end private diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 535b1e719..e3fdd44b1 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -98,6 +98,13 @@ class TypeDeChamp < ApplicationRecord cojo: 'cojo' } + ROUTABLE_TYPES = [ + type_champs.fetch(:drop_down_list), + type_champs.fetch(:communes), + type_champs.fetch(:departements), + type_champs.fetch(:regions) + ] + store_accessor :options, :cadastres, :old_pj, @@ -566,6 +573,10 @@ class TypeDeChamp < ApplicationRecord end end + def routable? + type_champ.in?(ROUTABLE_TYPES) + end + private DEFAULT_EMPTY = ['']