Skip to content

Commit

Permalink
move child? method for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
tchak committed Sep 17, 2024
1 parent 54132df commit 3fef831
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/dossier_champs_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def champs_for_prefill(stable_ids)
revision
.types_de_champ
.filter { _1.stable_id.in?(stable_ids) }
.filter { !revision.child?(_1) }
.filter { !_1.child?(revision) }
.map { _1.repetition? ? project_champ(_1, nil) : champ_for_update(_1, nil, updated_by: nil) }
end

Expand Down Expand Up @@ -129,7 +129,7 @@ def champ_with_attributes_for_update(type_de_champ, row_id, updated_by:)
end

def check_valid_row_id?(type_de_champ, row_id)
if revision.child?(type_de_champ)
if type_de_champ.child?(revision)
if row_id.blank?
raise "type_de_champ #{type_de_champ.stable_id} must have a row_id because it is part of a repetition"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/dossier_sections_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def sections_for(type_de_champ)
end

def auto_numbering_section_headers_for?(type_de_champ)
return false if revision.child?(type_de_champ)
return false if type_de_champ.child?(revision)

sections_for(type_de_champ)&.none? { _1.libelle =~ /^\d/ }
end
Expand Down
5 changes: 0 additions & 5 deletions app/models/procedure_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ def parent_of(tdc)
.find { _1.type_de_champ_id == tdc.id }.parent&.type_de_champ
end

def child?(tdc)
revision_types_de_champ
.find { _1.type_de_champ_id == tdc.id }&.child?
end

def remove_children_of(tdc)
children_of(tdc).each do |child|
remove_type_de_champ(child.stable_id)
Expand Down
4 changes: 4 additions & 0 deletions app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ def public?
!private?
end

def child?(revision)
revision.revision_types_de_champ.find { _1.type_de_champ_id == id }&.child?
end

def filename_for_attachement(attachment_sym)
attachment = send(attachment_sym)
if attachment.attached?
Expand Down

0 comments on commit 3fef831

Please sign in to comment.