Merge pull request #1434 from tchak/champs-type-and-private

Moulinette™ STI Champ et TypeDeChamp
This commit is contained in:
Paul Chavard 2018-02-21 10:36:39 +01:00 committed by GitHub
commit ffa8c313e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

View file

@ -50,7 +50,8 @@ class TypeDeChamp < ActiveRecord::Base
def params_for_champ
{
private: private?
private: private?,
type: "Champs::#{type_champ.classify}Champ"
}
end
@ -77,4 +78,8 @@ class TypeDeChamp < ActiveRecord::Base
def public?
!private?
end
def self.type_champ_to_class_name(type_champ)
"TypesDeChamp::#{type_champ.classify}TypeDeChamp"
end
end

View file

@ -18,6 +18,10 @@ class TypesDeChampService
parameters[attributes].each do |index, param|
param[:private] = private
if param[:type_champ]
param[:type] = TypeDeChamp.type_champ_to_class_name(param[:type_champ])
end
if param[:libelle].empty?
parameters[attributes].delete(index.to_s)
end

View file

@ -15,7 +15,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.irregular 'type_de_champ', 'types_de_champ'
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
inflect.irregular 'assign_to', 'assign_tos'
inflect.irregular('avis', 'avis')
inflect.uncountable(['avis', 'pays'])
end
# From https://github.com/davidcelis/inflections

View file

@ -0,0 +1,14 @@
namespace :'2018_02_13_fill_champ_private_and_type' do
task set: :environment do
Champ.includes(:type_de_champ).find_each do |champ|
champ.update_columns(champ.type_de_champ.params_for_champ)
end
TypeDeChamp.find_each do |type_de_champ|
type_de_champ.update_columns(
private: type_de_champ.private?,
type: TypeDeChamp.type_champ_to_class_name(type_de_champ.type_champ)
)
end
end
end