Merge pull request #1434 from tchak/champs-type-and-private
Moulinette™ STI Champ et TypeDeChamp
This commit is contained in:
commit
ffa8c313e8
4 changed files with 25 additions and 2 deletions
|
@ -50,7 +50,8 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
|
|
||||||
def params_for_champ
|
def params_for_champ
|
||||||
{
|
{
|
||||||
private: private?
|
private: private?,
|
||||||
|
type: "Champs::#{type_champ.classify}Champ"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,4 +78,8 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
def public?
|
def public?
|
||||||
!private?
|
!private?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.type_champ_to_class_name(type_champ)
|
||||||
|
"TypesDeChamp::#{type_champ.classify}TypeDeChamp"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,10 @@ class TypesDeChampService
|
||||||
|
|
||||||
parameters[attributes].each do |index, param|
|
parameters[attributes].each do |index, param|
|
||||||
param[:private] = private
|
param[:private] = private
|
||||||
|
if param[:type_champ]
|
||||||
|
param[:type] = TypeDeChamp.type_champ_to_class_name(param[:type_champ])
|
||||||
|
end
|
||||||
|
|
||||||
if param[:libelle].empty?
|
if param[:libelle].empty?
|
||||||
parameters[attributes].delete(index.to_s)
|
parameters[attributes].delete(index.to_s)
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
inflect.irregular 'type_de_champ', 'types_de_champ'
|
inflect.irregular 'type_de_champ', 'types_de_champ'
|
||||||
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
|
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
|
||||||
inflect.irregular 'assign_to', 'assign_tos'
|
inflect.irregular 'assign_to', 'assign_tos'
|
||||||
inflect.irregular('avis', 'avis')
|
inflect.uncountable(['avis', 'pays'])
|
||||||
end
|
end
|
||||||
|
|
||||||
# From https://github.com/davidcelis/inflections
|
# From https://github.com/davidcelis/inflections
|
||||||
|
|
14
lib/tasks/2018_02_13_fill_champ_private_and_type.rake
Normal file
14
lib/tasks/2018_02_13_fill_champ_private_and_type.rake
Normal 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
|
Loading…
Reference in a new issue