[#3356] Let dynamic type handle tag generation

This commit is contained in:
Frederic Merizen 2019-02-05 16:28:26 +01:00 committed by simon lehericey
parent 4a3d402a32
commit d3498e10bd
2 changed files with 15 additions and 14 deletions

View file

@ -38,6 +38,7 @@ class TypeDeChamp < ApplicationRecord
has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', dependent: :destroy
store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles, :old_pj
delegate :tags_for_template, to: :dynamic_type
# TODO simplify after migrating `options` column to (non YAML encoded) JSON
class MaybeYaml
@ -174,19 +175,6 @@ class TypeDeChamp < ApplicationRecord
end
end
def tags_for_template
l = libelle
[
{
libelle: l,
description: description,
lambda: -> (champs) {
champs.detect { |champ| champ.libelle == l }
}
}
]
end
private
def setup_procedure

View file

@ -1,9 +1,22 @@
class TypesDeChamp::TypeDeChampBase
include ActiveModel::Validations
delegate :libelle, to: :@type_de_champ
delegate :description, :libelle, to: :@type_de_champ
def initialize(type_de_champ)
@type_de_champ = type_de_champ
end
def tags_for_template
l = libelle
[
{
libelle: l,
description: description,
lambda: -> (champs) {
champs.detect { |champ| champ.libelle == l }
}
}
]
end
end