refactor(column): no more java 🎉 get_value -> value
This commit is contained in:
parent
af33e6a0e9
commit
7fddec484d
6 changed files with 26 additions and 40 deletions
|
@ -52,15 +52,12 @@ class Column
|
|||
procedure.find_column(h_id: h_id)
|
||||
end
|
||||
|
||||
def get_value(champ)
|
||||
def value(champ)
|
||||
return if champ.nil?
|
||||
|
||||
value = get_raw_value(champ)
|
||||
if should_cast?
|
||||
from_type = champ.last_write_column_type
|
||||
to_type = type
|
||||
parsed_value = parse_value(value, from_type)
|
||||
cast_value(parsed_value, from_type:, to_type:)
|
||||
value = typed_value(champ)
|
||||
if default_column?
|
||||
cast_value(value, from_type: champ.last_write_column_type, to_type: type)
|
||||
else
|
||||
value
|
||||
end
|
||||
|
@ -68,15 +65,15 @@ class Column
|
|||
|
||||
private
|
||||
|
||||
def get_raw_value(champ)
|
||||
champ.public_send(value_column)
|
||||
def typed_value(champ)
|
||||
value = string_value(champ)
|
||||
parse_value(value, type: champ.last_write_column_type)
|
||||
end
|
||||
|
||||
def should_cast?
|
||||
true
|
||||
end
|
||||
def string_value(champ) = champ.public_send(value_column)
|
||||
def default_column? = value_column.in?([:value, :external_id])
|
||||
|
||||
def parse_value(value, type)
|
||||
def parse_value(value, type:)
|
||||
return if value.blank?
|
||||
|
||||
case type
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Columns::DossierColumn < Column
|
||||
def get_value(dossier)
|
||||
def value(dossier)
|
||||
case table
|
||||
when 'self'
|
||||
dossier.public_send(column)
|
||||
|
|
|
@ -25,14 +25,10 @@ class Columns::JSONPathColumn < Column
|
|||
|
||||
private
|
||||
|
||||
def get_raw_value(champ)
|
||||
def typed_value(champ)
|
||||
champ.value_json&.dig(*value_column)
|
||||
end
|
||||
|
||||
def should_cast?
|
||||
false
|
||||
end
|
||||
|
||||
def stable_id
|
||||
@column
|
||||
end
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
|
||||
class Columns::LinkedDropDownColumn < Column
|
||||
def column
|
||||
if value_column == :value
|
||||
super
|
||||
else
|
||||
"#{@column}->#{value_column}" # override column otherwise json path facets will have same id as other
|
||||
end
|
||||
return super if default_column?
|
||||
"#{@column}->#{value_column}" # override column otherwise json path facets will have same id as other
|
||||
end
|
||||
|
||||
def filtered_ids(dossiers, values)
|
||||
|
@ -17,11 +14,11 @@ class Columns::LinkedDropDownColumn < Column
|
|||
|
||||
private
|
||||
|
||||
def get_raw_value(champ)
|
||||
def typed_value(champ)
|
||||
return nil if default_column?
|
||||
|
||||
primary_value, secondary_value = unpack_values(champ.value)
|
||||
case value_column
|
||||
when :value
|
||||
nil
|
||||
when :primary
|
||||
primary_value
|
||||
when :secondary
|
||||
|
@ -29,10 +26,6 @@ class Columns::LinkedDropDownColumn < Column
|
|||
end
|
||||
end
|
||||
|
||||
def should_cast?
|
||||
false
|
||||
end
|
||||
|
||||
def unpack_values(value)
|
||||
JSON.parse(value)
|
||||
rescue JSON::ParserError
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class Columns::TitreIdentiteColumn < Column
|
||||
private
|
||||
|
||||
def get_raw_value(champ)
|
||||
champ.piece_justificative_file.attached?.to_s
|
||||
def typed_value(champ)
|
||||
champ.piece_justificative_file.attached?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe Column do
|
||||
describe 'get_value' do
|
||||
describe 'value' do
|
||||
let(:groupe_instructeur) { create(:groupe_instructeur, instructeurs: [create(:instructeur)]) }
|
||||
|
||||
context 'when dossier columns' do
|
||||
|
@ -11,9 +11,9 @@ describe Column do
|
|||
let(:dossier) { create(:dossier, individual:, mandataire_first_name: "Martin", mandataire_last_name: "Christophe", for_tiers: true) }
|
||||
|
||||
it 'retrieve individual information' do
|
||||
expect(procedure.find_column(label: "Prénom").get_value(dossier)).to eq("Paul")
|
||||
expect(procedure.find_column(label: "Nom").get_value(dossier)).to eq("Sim")
|
||||
expect(procedure.find_column(label: "Civilité").get_value(dossier)).to eq("M.")
|
||||
expect(procedure.find_column(label: "Prénom").value(dossier)).to eq("Paul")
|
||||
expect(procedure.find_column(label: "Nom").value(dossier)).to eq("Sim")
|
||||
expect(procedure.find_column(label: "Civilité").value(dossier)).to eq("M.")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,7 @@ describe Column do
|
|||
let(:dossier) { create(:dossier, :en_instruction, :with_entreprise, procedure:) }
|
||||
|
||||
it 'retrieve entreprise information' do
|
||||
expect(procedure.find_column(label: "Libellé NAF").get_value(dossier)).to eq('Transports par conduites')
|
||||
expect(procedure.find_column(label: "Libellé NAF").value(dossier)).to eq('Transports par conduites')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -31,7 +31,7 @@ describe Column do
|
|||
let(:dossier) { create(:dossier, :en_instruction, procedure:) }
|
||||
|
||||
it 'does not fail' do
|
||||
expect(procedure.find_column(label: "Date décision SVA").get_value(dossier)).to eq(nil)
|
||||
expect(procedure.find_column(label: "Date décision SVA").value(dossier)).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -85,7 +85,7 @@ describe Column do
|
|||
type_de_champ = types_de_champ.find { _1.type_champ == type }
|
||||
champ = dossier.send(:filled_champ, type_de_champ, nil)
|
||||
columns = type_de_champ.columns(procedure_id: procedure.id)
|
||||
expect(columns.map { _1.get_value(champ) }).to eq(values)
|
||||
expect(columns.map { _1.value(champ) }).to eq(values)
|
||||
end
|
||||
|
||||
def retrieve_champ(type)
|
||||
|
|
Loading…
Reference in a new issue