Skip to content

Commit

Permalink
Reduce duplication in enum declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamineskola committed Nov 5, 2024
1 parent 7f53a40 commit aaa5db9
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 185 deletions.
2 changes: 1 addition & 1 deletion app/models/application_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ApplicationType < ApplicationRecord
other: "other"
}, scopes: false, instance_methods: false, validate: {on: :category}

enum :status, {inactive: "inactive", active: "active", retired: "retired"}
enum :status, %i[inactive active retired].index_with(&:to_s)

belongs_to :legislation, optional: true
has_many :planning_applications, dependent: :restrict_with_exception
Expand Down
48 changes: 22 additions & 26 deletions app/models/assessment_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,28 @@ class AssessmentDetail < ApplicationRecord
belongs_to :user
has_one :comment, as: :commentable, dependent: :destroy

enum :assessment_status, {
not_started: "not_started",
in_progress: "in_progress",
complete: "complete"
}, default: "not_started", prefix: "assessment"

enum :review_status, {
in_progress: "in_progress",
complete: "complete"
}, prefix: "review"

enum :reviewer_verdict, {
accepted: "accepted",
edited_and_accepted: "edited_and_accepted",
rejected: "rejected"
}

enum :category, {
summary_of_work: "summary_of_work",
site_description: "site_description",
consultation_summary: "consultation_summary",
additional_evidence: "additional_evidence",
neighbour_summary: "neighbour_summary",
amenity: "amenity",
check_publicity: "check_publicity"
}
enum :assessment_status, %i[not_started in_progress complete].index_with(&:to_s), default: "not_started", prefix: "assessment"

enum :review_status, %i[
in_progress
complete
].index_with(&:to_s), prefix: "review"

enum :reviewer_verdict, %i[
accepted
edited_and_accepted
rejected
].index_with(&:to_s)

enum :category, %i[
summary_of_work
site_description
consultation_summary
additional_evidence
neighbour_summary
amenity
check_publicity
].index_with(&:to_s)

CATEGORIES = defined_enums["category"].keys.map(&:to_sym).freeze

Expand Down
210 changes: 101 additions & 109 deletions app/models/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,115 +19,107 @@ class Audit < ApplicationRecord
).reorder(created_at: :desc)
}

enum :activity_type, {
approved: "approved",
assessed: "assessed",
assigned: "assigned",
archived: "archived",
unarchived: "unarchived",
submitted: "submitted",
withdrawn_recommendation: "withdrawn_recommendation",
challenged: "challenged",
created: "created",
constraint_added: "constraint_added",
constraint_removed: "constraint_removed",
determined: "determined",
red_line_created: "red_line_created",
red_line_updated: "red_line_updated",
invalidated: "invalidated",
returned: "returned",
updated: "updated",
uploaded: "uploaded",
started: "started",
withdrawn: "withdrawn",
closed: "closed",
heads_of_terms_validation_request_sent_post_validation: "heads_of_terms_validation_request_sent_post_validation",
heads_of_terms_validation_request_added: "heads_of_terms_validation_request_added",
heads_of_terms_validation_request_cancelled_post_validation: "heads_of_terms_validation_request_cancelled_post_validation",
heads_of_terms_validation_request_received: "heads_of_terms_validation_request_received",
pre_commencement_condition_validation_request_sent_post_validation: "pre_commencement_condition_validation_request_sent_post_validation",
pre_commencement_condition_validation_request_auto_closed: "pre_commencement_condition_validation_request_auto_closed",
pre_commencement_condition_validation_request_added: "pre_commencement_condition_validation_request_added",
pre_commencement_condition_validation_request_cancelled_post_validation: "pre_commencement_condition_validation_request_cancelled_post_validation",
pre_commencement_condition_validation_request_received: "pre_commencement_condition_validation_request_received",
red_line_boundary_change_validation_request_auto_closed: "red_line_boundary_change_validation_request_auto_closed",
description_change_validation_request_auto_closed: "description_change_validation_request_auto_closed",
document_invalidated: "document_invalidated",
document_changed_to_validated: "document_changed_to_validated",
document_received_at_changed: "document_received_at_changed",
description_change_validation_request_sent: "description_change_validation_request_sent",
description_change_validation_request_cancelled: "description_change_validation_request_cancelled",
description_change_validation_request_added: "description_change_validation_request_added",
description_change_validation_request_sent_post_validation: "description_change_validation_request_sent_post_validation",
description_change_validation_request_cancelled_post_validation: "description_change_validation_request_cancelled_post_validation",
replacement_document_validation_request_sent: "replacement_document_validation_request_sent",
replacement_document_validation_request_sent_post_validation:
"replacement_document_validation_request_sent_post_validation",
additional_document_validation_request_sent: "additional_document_validation_request_sent",
additional_document_validation_request_sent_post_validation:
"additional_document_validation_request_sent_post_validation",
red_line_boundary_change_validation_request_sent: "red_line_boundary_change_validation_request_sent",
red_line_boundary_change_validation_request_sent_post_validation:
"red_line_boundary_change_validation_request_sent_post_validation",
replacement_document_validation_request_added: "replacement_document_validation_request_added",
additional_document_validation_request_added: "additional_document_validation_request_added",
red_line_boundary_change_validation_request_added: "red_line_boundary_change_validation_request_added",
description_change_validation_request_received: "description_change_validation_request_received",
replacement_document_validation_request_received: "replacement_document_validation_request_received",
additional_document_validation_request_received: "additional_document_validation_request_received",
red_line_boundary_change_validation_request_received: "red_line_boundary_change_validation_request_received",
other_change_validation_request_added: "other_change_validation_request_added",
other_change_validation_request_sent: "other_change_validation_request_sent",
other_change_validation_request_received: "other_change_validation_request_received",
other_change_validation_request_sent_post_validation: "other_change_validation_request_sent_post_validation",
ownership_certificate_validation_request_added: "ownership_certificate_validation_request_added",
ownership_certificate_validation_request_received: "ownership_certificate_validation_request_received",
ownership_certificate_validation_request_sent: "ownership_certificate_validation_request_sent",
ownership_certificate_validation_request_cancelled: "ownership_certificate_validation_request_cancelled",
ownership_certificate_validation_request_sent_post_validation: "ownership_certificate_validation_request_sent_post_validation",
validation_requests_sent: "validation_requests_sent",
additional_document_validation_request_cancelled: "additional_document_validation_request_cancelled",
additional_document_validation_request_cancelled_post_validation:
"additional_document_validation_request_cancelled_post_validation",
other_change_validation_request_cancelled: "other_change_validation_request_cancelled",
fee_change_validation_request_cancelled: "fee_change_validation_request_cancelled",
fee_change_validation_request_added: "fee_change_validation_request_added",
fee_change_validation_request_sent: "fee_change_validation_request_sent",
fee_change_validation_request_sent_post_validation: "fee_change_validation_request_sent_post_validation",
fee_change_validation_request_received: "fee_change_validation_request_received",
proposal_measurements_updated: "proposal_measurements_updated",
red_line_boundary_change_validation_request_cancelled: "red_line_boundary_change_validation_request_cancelled",
red_line_boundary_change_validation_request_cancelled_post_validation:
"red_line_boundary_change_validation_request_cancelled_post_validation",
replacement_document_validation_request_cancelled: "replacement_document_validation_request_cancelled",
replacement_document_validation_request_cancelled_post_validation:
"replacement_document_validation_request_cancelled_post_validation",
time_extension_validation_request_added: "time_extension_validation_request_added",
time_extension_validation_request_sent_post_validation:
"time_extension_validation_request_sent_post_validation",
time_extension_validation_request_received: "time_extension_validation_request_received",
time_extension_validation_request_cancelled: "time_extension_validation_request_cancelled",
time_extension_validation_request_cancelled_post_validation:
"time_extension_validation_request_cancelled_post_validation",
time_extension_validation_request_sent: "time_extension_validation_request_sent",
constraints_checked: "constraints_checked",
neighbour_letters_sent: "neighbour_letters_sent",
neighbour_letter_copy_mail_sent: "neighbour_letter_copy_mail_sent",
neighbour_response_uploaded: "neighbour_response_uploaded",
neighbour_response_edited: "neighbour_response_edited",
legislation_checked: "legislation_checked",
press_notice: "press_notice",
press_notice_mail: "press_notice_mail",
site_notice_created: "site_notice_created",
consultee_emails_sent: "consultee_emails_sent",
consultee_emails_resent: "consultee_emails_resent",
consultees_reconsulted: "consultees_reconsulted",
consultee_response_uploaded: "consultee_response_uploaded",
consultee_response_edited: "consultee_response_edited",
committee_details_sent: "committee_details_sent",
sent_to_committee: "sent_to_committee",
review_cil_liability: "review_cil_liability"
}
enum :activity_type, %i[
approved
assessed
assigned
archived
unarchived
submitted
withdrawn_recommendation
challenged
created
constraint_added
constraint_removed
determined
red_line_created
red_line_updated
invalidated
returned
updated
uploaded
started
withdrawn
closed
heads_of_terms_validation_request_sent_post_validation
heads_of_terms_validation_request_added
heads_of_terms_validation_request_cancelled_post_validation
heads_of_terms_validation_request_received
pre_commencement_condition_validation_request_sent_post_validation
pre_commencement_condition_validation_request_auto_closed
pre_commencement_condition_validation_request_added
pre_commencement_condition_validation_request_cancelled_post_validation
pre_commencement_condition_validation_request_received
red_line_boundary_change_validation_request_auto_closed
description_change_validation_request_auto_closed
document_invalidated
document_changed_to_validated
document_received_at_changed
description_change_validation_request_sent
description_change_validation_request_cancelled
description_change_validation_request_added
description_change_validation_request_sent_post_validation
description_change_validation_request_cancelled_post_validation
replacement_document_validation_request_sent
replacement_document_validation_request_sent_post_validation
additional_document_validation_request_sent
additional_document_validation_request_sent_post_validation
red_line_boundary_change_validation_request_sent
red_line_boundary_change_validation_request_sent_post_validation
replacement_document_validation_request_added
additional_document_validation_request_added
red_line_boundary_change_validation_request_added
description_change_validation_request_received
replacement_document_validation_request_received
additional_document_validation_request_received
red_line_boundary_change_validation_request_received
other_change_validation_request_added
other_change_validation_request_sent
other_change_validation_request_received
other_change_validation_request_sent_post_validation
ownership_certificate_validation_request_added
ownership_certificate_validation_request_received
ownership_certificate_validation_request_sent
ownership_certificate_validation_request_cancelled
ownership_certificate_validation_request_sent_post_validation
validation_requests_sent
additional_document_validation_request_cancelled
additional_document_validation_request_cancelled_post_validation
other_change_validation_request_cancelled
fee_change_validation_request_cancelled
fee_change_validation_request_added
fee_change_validation_request_sent
fee_change_validation_request_sent_post_validation
fee_change_validation_request_received
proposal_measurements_updated
red_line_boundary_change_validation_request_cancelled
red_line_boundary_change_validation_request_cancelled_post_validation
replacement_document_validation_request_cancelled
replacement_document_validation_request_cancelled_post_validation
time_extension_validation_request_added
time_extension_validation_request_sent_post_validation
time_extension_validation_request_received
time_extension_validation_request_cancelled
time_extension_validation_request_cancelled_post_validation
time_extension_validation_request_sent
constraints_checked
neighbour_letters_sent
neighbour_letter_copy_mail_sent
neighbour_response_uploaded
neighbour_response_edited
legislation_checked
press_notice
press_notice_mail
site_notice_created
consultee_emails_sent
consultee_emails_resent
consultees_reconsulted
consultee_response_uploaded
consultee_response_edited
committee_details_sent
sent_to_committee
review_cil_liability
].index_with(&:to_s)

validates :activity_type, presence: true

Expand Down
12 changes: 6 additions & 6 deletions app/models/consultation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ class AddNeighbourAddressesError < StandardError; end
accepts_nested_attributes_for :consultees
accepts_nested_attributes_for :neighbours, reject_if: :neighbour_exists?

enum :status, {
not_started: "not_started",
in_progress: "in_progress",
complete: "complete",
to_be_reviewed: "to_be_reviewed"
}
enum :status, %i[
not_started
in_progress
complete
to_be_reviewed
].index_with(&:to_s)

before_update :audit_letter_copy_sent!, if: :letter_copy_sent_at_changed?

Expand Down
2 changes: 1 addition & 1 deletion app/models/neighbour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AddressValidationError < StandardError; end
has_many :neighbour_letters, dependent: :destroy
has_many :neighbour_responses, dependent: :destroy

enum :source, {manual_add: "manual_add", map_selection: "map_selection", sent_comment: "sent_comment"}
enum :source, %i[manual_add map_selection sent_comment].index_with(&:to_s)

validates :address, presence: true, unless: :not_selected?
validates :address, uniqueness: {
Expand Down
24 changes: 12 additions & 12 deletions app/models/permitted_development_right.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class NotCreatableError < StandardError; end
validates :removed_reason, if: :removed
end

enum :status, {
in_progress: "in_progress",
checked: "checked",
removed: "removed",
to_be_reviewed: "to_be_reviewed"
}

enum :review_status, {
review_not_started: "review_not_started",
review_in_progress: "review_in_progress",
review_complete: "review_complete"
}
enum :status, %i[
in_progress
checked
removed
to_be_reviewed
].index_with(&:to_s)

enum :review_status, %i[
review_not_started
review_in_progress
review_complete
].index_with(&:to_s)

validate :reviewer_is_present?
validate :planning_application_can_review_assessment
Expand Down
14 changes: 7 additions & 7 deletions app/models/planning_application_constraint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
class PlanningApplicationConstraint < ApplicationRecord
include Auditable

enum :status, {
pending: "pending",
success: "success",
failed: "failed",
not_found: "not_found",
removed: "removed"
}
enum :status, %i[
pending
success
failed
not_found
removed
].index_with(&:to_s)

belongs_to :planning_application
belongs_to :planning_application_constraints_query, optional: true
Expand Down
Loading

0 comments on commit aaa5db9

Please sign in to comment.