From e2b922acfff38d5211d7bb68204691f7011109dc Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Fri, 3 Jan 2025 21:30:19 -0800 Subject: [PATCH 1/3] Define enums by positional args --- app/models/field_slip_job_tracker.rb | 7 +-- app/models/location_description.rb | 11 ++--- app/models/name_description.rb | 20 ++------ app/models/project_member.rb | 7 +-- app/models/user.rb | 71 +++++++--------------------- 5 files changed, 28 insertions(+), 88 deletions(-) diff --git a/app/models/field_slip_job_tracker.rb b/app/models/field_slip_job_tracker.rb index c128b80db7..7b8c5f084e 100644 --- a/app/models/field_slip_job_tracker.rb +++ b/app/models/field_slip_job_tracker.rb @@ -5,12 +5,7 @@ class FieldSlipJobTracker < AbstractModel SUBDIR = "shared" PDF_DIR = PUBLIC_DIR + SUBDIR - enum status: - { - Starting: 1, - Processing: 2, - Done: 3 - } + enum :status, { Starting: 1, Processing: 2, Done: 3 } belongs_to :user diff --git a/app/models/location_description.rb b/app/models/location_description.rb index 614724c8f9..ca22bd8683 100644 --- a/app/models/location_description.rb +++ b/app/models/location_description.rb @@ -52,14 +52,9 @@ class LocationDescription < Description # enum definitions for use by simple_enum gem # Do not change the integer associated with a value - enum source_type: - { - public: 1, - foreign: 2, - project: 3, - source: 4, - user: 5 - }, _suffix: :source + enum :source_type, + { public: 1, foreign: 2, project: 3, source: 4, user: 5 }, + suffix: :source, instance_methods: false belongs_to :license belongs_to :location diff --git a/app/models/name_description.rb b/app/models/name_description.rb index e7dd971347..47fa6d7db3 100644 --- a/app/models/name_description.rb +++ b/app/models/name_description.rb @@ -67,21 +67,11 @@ class NameDescription < Description # enum definitions for use by simple_enum gem # Do not change the integer associated with a value - enum review_status: - { - unreviewed: 1, - unvetted: 2, - vetted: 3, - inaccurate: 4 - } - enum source_type: - { - public: 1, - foreign: 2, - project: 3, - source: 4, - user: 5 - }, _suffix: :source + enum :review_status, { unreviewed: 1, unvetted: 2, vetted: 3, inaccurate: 4 } + + enum :source_type, { public: 1, foreign: 2, project: 3, source: 4, user: 5 }, + suffix: :source, instance_methods: false + belongs_to :license belongs_to :name belongs_to :project diff --git a/app/models/project_member.rb b/app/models/project_member.rb index f65494a49b..3b7d69fd01 100644 --- a/app/models/project_member.rb +++ b/app/models/project_member.rb @@ -1,12 +1,7 @@ # frozen_string_literal: true class ProjectMember < ApplicationRecord - enum trust_level: - { - no_trust: 1, - hidden_gps: 2, - editing: 3 - } + enum :trust_level, { no_trust: 1, hidden_gps: 2, editing: 3 } belongs_to :project belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index 9d65b30fe9..d5480bc3ce 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -202,59 +202,24 @@ class User < AbstractModel # rubocop:disable Metrics/ClassLength # enum definitions for use by simple_enum gem # Do not change the integer associated with a value # first value is the default - enum thumbnail_size: - { - thumbnail: 1, - small: 2 - }, - _prefix: :thumb_size, - _default: "thumbnail" - - enum image_size: - { - thumbnail: 1, - small: 2, - medium: 3, - large: 4, - huge: 5, - full_size: 6 - }, - _prefix: true, - _default: "medium" - - enum votes_anonymous: - { - no: 1, - yes: 2, - old: 3 - }, - _prefix: :votes_anon, - _default: "no" - - enum location_format: - { - postal: 1, - scientific: 2 - }, - _prefix: true, - _default: "postal" - - enum hide_authors: - { - none: 1, - above_species: 2 - }, - _prefix: true, - _default: "none" - - enum keep_filenames: - { - toss: 1, - keep_but_hide: 2, - keep_and_show: 3 - }, - _suffix: :filenames, - _default: "toss" + enum :thumbnail_size, { thumbnail: 1, small: 2 }, + prefix: :thumb_size, default: "thumbnail", instance_methods: false + + enum :image_size, + { thumbnail: 1, small: 2, medium: 3, large: 4, huge: 5, full_size: 6 }, + prefix: true, default: "medium", instance_methods: false + + enum :votes_anonymous, { no: 1, yes: 2, old: 3 }, + prefix: :votes_anon, default: "no", instance_methods: false + + enum :location_format, { postal: 1, scientific: 2 }, + prefix: true, default: "postal", instance_methods: false + + enum :hide_authors, { none: 1, above_species: 2 }, + prefix: true, default: "none", instance_methods: false + + enum :keep_filenames, { toss: 1, keep_but_hide: 2, keep_and_show: 3 }, + suffix: :filenames, default: "toss", instance_methods: false has_one :user_stats, dependent: :destroy From e2acbb4e7056fad8e63df0100d006b4e1ef601fa Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Fri, 3 Jan 2025 21:38:50 -0800 Subject: [PATCH 2/3] Update name_description.rb --- app/models/name_description.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/name_description.rb b/app/models/name_description.rb index 47fa6d7db3..1f73f6678c 100644 --- a/app/models/name_description.rb +++ b/app/models/name_description.rb @@ -67,7 +67,7 @@ class NameDescription < Description # enum definitions for use by simple_enum gem # Do not change the integer associated with a value - enum :review_status, { unreviewed: 1, unvetted: 2, vetted: 3, inaccurate: 4 } + enum :review_status, { unreviewed: 1, unvetted: 2, vetted: 3, inaccurate: 4 } enum :source_type, { public: 1, foreign: 2, project: 3, source: 4, user: 5 }, suffix: :source, instance_methods: false From 6cee96cc715ef8e58549daf282686b37bb87049f Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Fri, 3 Jan 2025 21:42:27 -0800 Subject: [PATCH 3/3] Cleanup --- app/models/location_description.rb | 1 - app/models/name.rb | 1 - app/models/name_description.rb | 1 - app/models/user.rb | 15 +++++++-------- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/models/location_description.rb b/app/models/location_description.rb index ca22bd8683..e6f14cd9b2 100644 --- a/app/models/location_description.rb +++ b/app/models/location_description.rb @@ -50,7 +50,6 @@ class LocationDescription < Description require "acts_as_versioned" - # enum definitions for use by simple_enum gem # Do not change the integer associated with a value enum :source_type, { public: 1, foreign: 2, project: 3, source: 4, user: 5 }, diff --git a/app/models/name.rb b/app/models/name.rb index e3b8c3ea84..473758646d 100644 --- a/app/models/name.rb +++ b/app/models/name.rb @@ -348,7 +348,6 @@ class Name < AbstractModel extend Parse extend Create - # enum definitions for use by simple_enum gem # Do not change the integer associated with a value enum :rank, { Form: 1, diff --git a/app/models/name_description.rb b/app/models/name_description.rb index 1f73f6678c..93fc93046b 100644 --- a/app/models/name_description.rb +++ b/app/models/name_description.rb @@ -65,7 +65,6 @@ class NameDescription < Description require "acts_as_versioned" - # enum definitions for use by simple_enum gem # Do not change the integer associated with a value enum :review_status, { unreviewed: 1, unvetted: 2, vetted: 3, inaccurate: 4 } diff --git a/app/models/user.rb b/app/models/user.rb index d5480bc3ce..0d23a99ed8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -199,27 +199,26 @@ class User < AbstractModel # rubocop:disable Metrics/ClassLength require "digest/sha1" - # enum definitions for use by simple_enum gem # Do not change the integer associated with a value - # first value is the default + # First value is the default enum :thumbnail_size, { thumbnail: 1, small: 2 }, - prefix: :thumb_size, default: "thumbnail", instance_methods: false + prefix: :thumb_size, default: :thumbnail, instance_methods: false enum :image_size, { thumbnail: 1, small: 2, medium: 3, large: 4, huge: 5, full_size: 6 }, - prefix: true, default: "medium", instance_methods: false + prefix: true, default: :medium, instance_methods: false enum :votes_anonymous, { no: 1, yes: 2, old: 3 }, - prefix: :votes_anon, default: "no", instance_methods: false + prefix: :votes_anon, default: :no, instance_methods: false enum :location_format, { postal: 1, scientific: 2 }, - prefix: true, default: "postal", instance_methods: false + prefix: true, default: :postal, instance_methods: false enum :hide_authors, { none: 1, above_species: 2 }, - prefix: true, default: "none", instance_methods: false + prefix: true, default: :none, instance_methods: false enum :keep_filenames, { toss: 1, keep_but_hide: 2, keep_and_show: 3 }, - suffix: :filenames, default: "toss", instance_methods: false + suffix: :filenames, default: :toss, instance_methods: false has_one :user_stats, dependent: :destroy