From beadb873fe45fe9bf4e88364f03cc0f05a55f461 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:30:13 -0400 Subject: [PATCH 01/21] use new Parent Class --- app/models/preneeds/address.rb | 2 +- app/models/preneeds/applicant.rb | 2 +- app/models/preneeds/burial_form.rb | 2 +- app/models/preneeds/claimant.rb | 2 +- app/models/preneeds/currently_buried_person.rb | 2 +- app/models/preneeds/date_range.rb | 2 +- app/models/preneeds/full_name.rb | 2 +- app/models/preneeds/preneed_attachment_hash.rb | 2 +- app/models/preneeds/race.rb | 2 +- app/models/preneeds/service_record.rb | 2 +- app/models/preneeds/veteran.rb | 2 +- app/models/preneeds/{base.rb => virtus_base.rb} | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) rename app/models/preneeds/{base.rb => virtus_base.rb} (96%) diff --git a/app/models/preneeds/address.rb b/app/models/preneeds/address.rb index f1c94f9dc9b..9f5e6d46c30 100644 --- a/app/models/preneeds/address.rb +++ b/app/models/preneeds/address.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute postal_code # @return [String] address postal code # - class Address < Preneeds::Base + class Address < Preneeds::VirtusBase attribute :street, String attribute :street2, String attribute :city, String diff --git a/app/models/preneeds/applicant.rb b/app/models/preneeds/applicant.rb index fca86d04b08..f75bb1647f4 100644 --- a/app/models/preneeds/applicant.rb +++ b/app/models/preneeds/applicant.rb @@ -18,7 +18,7 @@ module Preneeds # @!attribute name # @return [Preneeds::FullName] applicant's name # - class Applicant < Preneeds::Base + class Applicant < Preneeds::VirtusBase attribute :applicant_email, String attribute :applicant_phone_number, String attribute :applicant_relationship_to_claimant, String diff --git a/app/models/preneeds/burial_form.rb b/app/models/preneeds/burial_form.rb index 3145e25efca..0713a1cfc00 100644 --- a/app/models/preneeds/burial_form.rb +++ b/app/models/preneeds/burial_form.rb @@ -33,7 +33,7 @@ module Preneeds # @!attribute veteran # @return [Preneeds::Veteran] Veteran object. Veteran is the person who is the owner of the benefit. # - class BurialForm < Preneeds::Base + class BurialForm < Preneeds::VirtusBase # Preneeds Burial Form official form id # FORM = '40-10007' diff --git a/app/models/preneeds/claimant.rb b/app/models/preneeds/claimant.rb index d198874e46b..fcbaa74aef9 100644 --- a/app/models/preneeds/claimant.rb +++ b/app/models/preneeds/claimant.rb @@ -22,7 +22,7 @@ module Preneeds # @!attribute address # @return [Preneeds::Address] claimant's address # - class Claimant < Preneeds::Base + class Claimant < Preneeds::VirtusBase attribute :date_of_birth, String attribute :desired_cemetery, String attribute :email, String diff --git a/app/models/preneeds/currently_buried_person.rb b/app/models/preneeds/currently_buried_person.rb index b5e8023ce26..b4fe917c83a 100644 --- a/app/models/preneeds/currently_buried_person.rb +++ b/app/models/preneeds/currently_buried_person.rb @@ -10,7 +10,7 @@ module Preneeds # @!attribute name # @return [Preneeds::FullName] currently buried person's full name # - class CurrentlyBuriedPerson < Preneeds::Base + class CurrentlyBuriedPerson < Preneeds::VirtusBase attribute :cemetery_number, String attribute :name, Preneeds::FullName diff --git a/app/models/preneeds/date_range.rb b/app/models/preneeds/date_range.rb index f1bcbe8790a..104645dd7c6 100644 --- a/app/models/preneeds/date_range.rb +++ b/app/models/preneeds/date_range.rb @@ -8,7 +8,7 @@ module Preneeds # @!attribute to # @return [String] 'to' date # - class DateRange < Preneeds::Base + class DateRange < Preneeds::VirtusBase attribute :from, String attribute :to, String diff --git a/app/models/preneeds/full_name.rb b/app/models/preneeds/full_name.rb index feb1f1c8844..aa3b87157bf 100644 --- a/app/models/preneeds/full_name.rb +++ b/app/models/preneeds/full_name.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute suffix # @return [String] name suffix # - class FullName < Preneeds::Base + class FullName < Preneeds::VirtusBase attribute :first, String attribute :last, String attribute :maiden, String diff --git a/app/models/preneeds/preneed_attachment_hash.rb b/app/models/preneeds/preneed_attachment_hash.rb index 7cac5fe5d6c..1ddd297a07e 100644 --- a/app/models/preneeds/preneed_attachment_hash.rb +++ b/app/models/preneeds/preneed_attachment_hash.rb @@ -11,7 +11,7 @@ module Preneeds # @!attribute name # @return [String] attachment file name # - class PreneedAttachmentHash < Preneeds::Base + class PreneedAttachmentHash < Preneeds::VirtusBase attribute :confirmation_code, String attribute :attachment_id, String attribute :name, String diff --git a/app/models/preneeds/race.rb b/app/models/preneeds/race.rb index 340d287f0aa..1388d2209b4 100644 --- a/app/models/preneeds/race.rb +++ b/app/models/preneeds/race.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Preneeds - class Race < Preneeds::Base + class Race < Preneeds::VirtusBase ATTRIBUTE_MAPPING = { 'I' => :is_american_indian_or_alaskan_native, 'A' => :is_asian, diff --git a/app/models/preneeds/service_record.rb b/app/models/preneeds/service_record.rb index 75631d82e59..89f4f85a39b 100644 --- a/app/models/preneeds/service_record.rb +++ b/app/models/preneeds/service_record.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute date_range # @return [Preneeds::DateRange] service date range # - class ServiceRecord < Preneeds::Base + class ServiceRecord < Preneeds::VirtusBase attribute :service_branch, String attribute :discharge_type, String attribute :highest_rank, String diff --git a/app/models/preneeds/veteran.rb b/app/models/preneeds/veteran.rb index f898e06846b..8fb99066903 100644 --- a/app/models/preneeds/veteran.rb +++ b/app/models/preneeds/veteran.rb @@ -34,7 +34,7 @@ module Preneeds # @!attribute service_records # @return [Array] veteran's service records # - class Veteran < Preneeds::Base + class Veteran < Preneeds::VirtusBase attribute :date_of_birth, String attribute :date_of_death, String attribute :gender, String diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/virtus_base.rb similarity index 96% rename from app/models/preneeds/base.rb rename to app/models/preneeds/virtus_base.rb index 594d5a40c7a..b7284621c9d 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/virtus_base.rb @@ -4,7 +4,7 @@ module Preneeds # Parent class for other Preneeds Burial form related models # Should not be initialized directly # - class Base + class VirtusBase extend ActiveModel::Naming include Virtus.model(nullify_blank: true) From a264aa0d34bb2dd4b39520ba7481239ac33e4ce5 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:26:29 -0400 Subject: [PATCH 02/21] proof of concept for replacing Virtus models --- app/models/preneeds/address.rb | 2 +- app/models/preneeds/applicant.rb | 14 +++--- app/models/preneeds/base.rb | 86 ++++++++++++++++++++++++++++++++ app/models/preneeds/full_name.rb | 2 +- 4 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 app/models/preneeds/base.rb diff --git a/app/models/preneeds/address.rb b/app/models/preneeds/address.rb index 9f5e6d46c30..f1c94f9dc9b 100644 --- a/app/models/preneeds/address.rb +++ b/app/models/preneeds/address.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute postal_code # @return [String] address postal code # - class Address < Preneeds::VirtusBase + class Address < Preneeds::Base attribute :street, String attribute :street2, String attribute :city, String diff --git a/app/models/preneeds/applicant.rb b/app/models/preneeds/applicant.rb index f75bb1647f4..2f37c246a7a 100644 --- a/app/models/preneeds/applicant.rb +++ b/app/models/preneeds/applicant.rb @@ -18,14 +18,14 @@ module Preneeds # @!attribute name # @return [Preneeds::FullName] applicant's name # - class Applicant < Preneeds::VirtusBase - attribute :applicant_email, String - attribute :applicant_phone_number, String - attribute :applicant_relationship_to_claimant, String - attribute :completing_reason, String, default: 'vets.gov application' +class Applicant < Preneeds::Base + attribute :applicant_email, String + attribute :applicant_phone_number, String + attribute :applicant_relationship_to_claimant, String + attribute :completing_reason, String, default: 'vets.gov application' - attribute :mailing_address, Preneeds::Address - attribute :name, Preneeds::FullName + attribute :mailing_address, Preneeds::Address + attribute :name, Preneeds::FullName # (see Preneeds::BurialForm#as_eoas) # diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb new file mode 100644 index 00000000000..0a6486e4852 --- /dev/null +++ b/app/models/preneeds/base.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +# Parent class for other Preneeds Burial form related models +# Should not be initialized directly +# +module Preneeds + class Base + extend ActiveModel::Naming + include ActiveModel::Model + include ActiveModel::Serializers::JSON + + @@attributes = {} + + class << self + attr_reader :attributes + + # Class method to define a setter & getter for attribute + # this will also coerce a hash to the require class + # doesn't currently coerce scalar classes such as string to int + # + # @param name [Symbol] the name of the attribute + # @param klass [Class] the class of the attribute + # @param default [String|Integer] the default value of the attribute + # + def attribute(name, klass, default: nil) + @@attributes[name] = { type: klass, default: default } + + # Define a getter method for the attribute + define_method(name) do + instance_variable_get("@#{name}") || default + end + + # Define a setter method for the attribute + define_method("#{name}=") do |value| + if value.is_a?(Hash) + value = klass.new(value) + end + + if value.is_a?(klass) || value.nil? + instance_variable_set("@#{name}", value) + else + raise TypeError, "#{name} must be a #{klass}" + end + end + end + + def attribute_set + @@attributes.keys + end + end + + # Acts as ActiveRecord::Base#attributes which is needed + # for serialization + # + def attributes + nested_attributes(instance_values) + end + + # Override `as_json` + # + # @param options [Hash] + # + # @see ActiveModel::Serializers::JSON + # + def as_json(options = {}) + super(options).deep_transform_keys { |key| key.camelize(:lower) } + end + + private + + # Collect values from attribute and nested objects + # + # @param values [Hash] + # + # @return [Hash] nested attributes + def nested_attributes(values) + values.transform_values do |value| + if value.respond_to?(:instance_values) + nested_attributes(value.instance_values) + else + value + end + end + end + end +end diff --git a/app/models/preneeds/full_name.rb b/app/models/preneeds/full_name.rb index aa3b87157bf..feb1f1c8844 100644 --- a/app/models/preneeds/full_name.rb +++ b/app/models/preneeds/full_name.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute suffix # @return [String] name suffix # - class FullName < Preneeds::VirtusBase + class FullName < Preneeds::Base attribute :first, String attribute :last, String attribute :maiden, String From e1caeb7e6b7ecf9e9b5d6219a89f9101b433077e Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:28:06 -0400 Subject: [PATCH 03/21] fix formatting --- app/models/preneeds/applicant.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/preneeds/applicant.rb b/app/models/preneeds/applicant.rb index 2f37c246a7a..fca86d04b08 100644 --- a/app/models/preneeds/applicant.rb +++ b/app/models/preneeds/applicant.rb @@ -18,14 +18,14 @@ module Preneeds # @!attribute name # @return [Preneeds::FullName] applicant's name # -class Applicant < Preneeds::Base - attribute :applicant_email, String - attribute :applicant_phone_number, String - attribute :applicant_relationship_to_claimant, String - attribute :completing_reason, String, default: 'vets.gov application' + class Applicant < Preneeds::Base + attribute :applicant_email, String + attribute :applicant_phone_number, String + attribute :applicant_relationship_to_claimant, String + attribute :completing_reason, String, default: 'vets.gov application' - attribute :mailing_address, Preneeds::Address - attribute :name, Preneeds::FullName + attribute :mailing_address, Preneeds::Address + attribute :name, Preneeds::FullName # (see Preneeds::BurialForm#as_eoas) # From b7ac0e64174267028bdbb4545f498f92e6e60520 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:56:55 -0400 Subject: [PATCH 04/21] use a class instance variable instead of class variable --- app/models/preneeds/base.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 0a6486e4852..ea9d0c20e8e 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -9,10 +9,13 @@ class Base include ActiveModel::Model include ActiveModel::Serializers::JSON - @@attributes = {} + @attributes = {} class << self - attr_reader :attributes + + def attributes + @attributes ||= {} + end # Class method to define a setter & getter for attribute # this will also coerce a hash to the require class @@ -23,7 +26,7 @@ class << self # @param default [String|Integer] the default value of the attribute # def attribute(name, klass, default: nil) - @@attributes[name] = { type: klass, default: default } + attributes[name] = { type: klass, default: default } # Define a getter method for the attribute define_method(name) do @@ -45,7 +48,7 @@ def attribute(name, klass, default: nil) end def attribute_set - @@attributes.keys + attributes.keys end end From e2f01e86a92b891b1708194d7eb413c9187829dd Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:02:20 -0400 Subject: [PATCH 05/21] linting --- app/models/preneeds/base.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index ea9d0c20e8e..36b40494fc6 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -9,7 +9,7 @@ class Base include ActiveModel::Model include ActiveModel::Serializers::JSON - @attributes = {} + @attributes = {}.freeze class << self @@ -26,7 +26,7 @@ def attributes # @param default [String|Integer] the default value of the attribute # def attribute(name, klass, default: nil) - attributes[name] = { type: klass, default: default } + attributes[name] = { type: klass, default: } # Define a getter method for the attribute define_method(name) do @@ -35,9 +35,7 @@ def attribute(name, klass, default: nil) # Define a setter method for the attribute define_method("#{name}=") do |value| - if value.is_a?(Hash) - value = klass.new(value) - end + value = klass.new(value) if value.is_a?(Hash) if value.is_a?(klass) || value.nil? instance_variable_set("@#{name}", value) From 4fddc3d58ede4bddb385357f977cd5cc725af13d Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:01:03 -0400 Subject: [PATCH 06/21] revert back to class variable for attributes --- .rubocop_todo.yml | 4 ++++ app/models/preneeds/base.rb | 13 ++++--------- spec/models/preneeds/applicant_spec.rb | 1 + 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 565bc6147ed..42a8395fb03 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1228,3 +1228,7 @@ ThreadSafety/InstanceVariableInClassMethod: - 'lib/va_profile/contact_information/transaction_response.rb' - 'lib/vic/url_helper.rb' - 'modules/mobile/app/models/mobile/v0/concerns/redis_caching.rb' + +Style/ClassVars: + Exclude: + - 'app/models/preneeds/base.rb' diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 36b40494fc6..325e3e1a05a 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -9,13 +9,10 @@ class Base include ActiveModel::Model include ActiveModel::Serializers::JSON - @attributes = {}.freeze + @@attributes = {} class << self - - def attributes - @attributes ||= {} - end + attr_reader :attributes # Class method to define a setter & getter for attribute # this will also coerce a hash to the require class @@ -26,14 +23,12 @@ def attributes # @param default [String|Integer] the default value of the attribute # def attribute(name, klass, default: nil) - attributes[name] = { type: klass, default: } + @@attributes[name] = { type: klass, default: } - # Define a getter method for the attribute define_method(name) do instance_variable_get("@#{name}") || default end - # Define a setter method for the attribute define_method("#{name}=") do |value| value = klass.new(value) if value.is_a?(Hash) @@ -46,7 +41,7 @@ def attribute(name, klass, default: nil) end def attribute_set - attributes.keys + @@attributes.keys end end diff --git a/spec/models/preneeds/applicant_spec.rb b/spec/models/preneeds/applicant_spec.rb index f7ea9015dc1..11a8d3dfe58 100644 --- a/spec/models/preneeds/applicant_spec.rb +++ b/spec/models/preneeds/applicant_spec.rb @@ -19,6 +19,7 @@ describe 'when converting to eoas' do it 'produces an ordered hash' do + binding.pry expect(subject.as_eoas.keys).to eq( %i[ applicantEmail applicantPhoneNumber applicantRelationshipToClaimant From 76818e35682f47a938115082659b71d4755f373c Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:59:50 -0400 Subject: [PATCH 07/21] clean up and add comments --- app/models/preneeds/base.rb | 7 +++++-- spec/models/preneeds/applicant_spec.rb | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 325e3e1a05a..d2a2c5b5d88 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -9,11 +9,12 @@ class Base include ActiveModel::Model include ActiveModel::Serializers::JSON + # This class variable is an acceptable use case, because + # the values are only set via implicit receiver and I want + # subclasses to have shared attributes @@attributes = {} class << self - attr_reader :attributes - # Class method to define a setter & getter for attribute # this will also coerce a hash to the require class # doesn't currently coerce scalar classes such as string to int @@ -25,10 +26,12 @@ class << self def attribute(name, klass, default: nil) @@attributes[name] = { type: klass, default: } + # Define a getter method for the attribute define_method(name) do instance_variable_get("@#{name}") || default end + # Define a setter method for the attribute define_method("#{name}=") do |value| value = klass.new(value) if value.is_a?(Hash) diff --git a/spec/models/preneeds/applicant_spec.rb b/spec/models/preneeds/applicant_spec.rb index 11a8d3dfe58..f7ea9015dc1 100644 --- a/spec/models/preneeds/applicant_spec.rb +++ b/spec/models/preneeds/applicant_spec.rb @@ -19,7 +19,6 @@ describe 'when converting to eoas' do it 'produces an ordered hash' do - binding.pry expect(subject.as_eoas.keys).to eq( %i[ applicantEmail applicantPhoneNumber applicantRelationshipToClaimant From 74fe4200634ae610e6cf7cbf0f45bff74777c08e Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:18:36 -0400 Subject: [PATCH 08/21] fix merge error --- app/models/preneeds/address.rb | 2 +- app/models/preneeds/applicant.rb | 2 +- app/models/preneeds/base.rb | 85 ++++++++++++++++++++++++++++++++ app/models/preneeds/full_name.rb | 2 +- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 app/models/preneeds/base.rb diff --git a/app/models/preneeds/address.rb b/app/models/preneeds/address.rb index 9f5e6d46c30..f1c94f9dc9b 100644 --- a/app/models/preneeds/address.rb +++ b/app/models/preneeds/address.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute postal_code # @return [String] address postal code # - class Address < Preneeds::VirtusBase + class Address < Preneeds::Base attribute :street, String attribute :street2, String attribute :city, String diff --git a/app/models/preneeds/applicant.rb b/app/models/preneeds/applicant.rb index f75bb1647f4..fca86d04b08 100644 --- a/app/models/preneeds/applicant.rb +++ b/app/models/preneeds/applicant.rb @@ -18,7 +18,7 @@ module Preneeds # @!attribute name # @return [Preneeds::FullName] applicant's name # - class Applicant < Preneeds::VirtusBase + class Applicant < Preneeds::Base attribute :applicant_email, String attribute :applicant_phone_number, String attribute :applicant_relationship_to_claimant, String diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb new file mode 100644 index 00000000000..d2a2c5b5d88 --- /dev/null +++ b/app/models/preneeds/base.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +# Parent class for other Preneeds Burial form related models +# Should not be initialized directly +# +module Preneeds + class Base + extend ActiveModel::Naming + include ActiveModel::Model + include ActiveModel::Serializers::JSON + + # This class variable is an acceptable use case, because + # the values are only set via implicit receiver and I want + # subclasses to have shared attributes + @@attributes = {} + + class << self + # Class method to define a setter & getter for attribute + # this will also coerce a hash to the require class + # doesn't currently coerce scalar classes such as string to int + # + # @param name [Symbol] the name of the attribute + # @param klass [Class] the class of the attribute + # @param default [String|Integer] the default value of the attribute + # + def attribute(name, klass, default: nil) + @@attributes[name] = { type: klass, default: } + + # Define a getter method for the attribute + define_method(name) do + instance_variable_get("@#{name}") || default + end + + # Define a setter method for the attribute + define_method("#{name}=") do |value| + value = klass.new(value) if value.is_a?(Hash) + + if value.is_a?(klass) || value.nil? + instance_variable_set("@#{name}", value) + else + raise TypeError, "#{name} must be a #{klass}" + end + end + end + + def attribute_set + @@attributes.keys + end + end + + # Acts as ActiveRecord::Base#attributes which is needed + # for serialization + # + def attributes + nested_attributes(instance_values) + end + + # Override `as_json` + # + # @param options [Hash] + # + # @see ActiveModel::Serializers::JSON + # + def as_json(options = {}) + super(options).deep_transform_keys { |key| key.camelize(:lower) } + end + + private + + # Collect values from attribute and nested objects + # + # @param values [Hash] + # + # @return [Hash] nested attributes + def nested_attributes(values) + values.transform_values do |value| + if value.respond_to?(:instance_values) + nested_attributes(value.instance_values) + else + value + end + end + end + end +end diff --git a/app/models/preneeds/full_name.rb b/app/models/preneeds/full_name.rb index aa3b87157bf..feb1f1c8844 100644 --- a/app/models/preneeds/full_name.rb +++ b/app/models/preneeds/full_name.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute suffix # @return [String] name suffix # - class FullName < Preneeds::VirtusBase + class FullName < Preneeds::Base attribute :first, String attribute :last, String attribute :maiden, String From fbd796bee287a9006157e3890c120a6c48c5b8db Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:42:44 -0400 Subject: [PATCH 09/21] move rubocop disable to base class --- .rubocop_todo.yml | 4 ---- app/models/preneeds/base.rb | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 42a8395fb03..565bc6147ed 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1228,7 +1228,3 @@ ThreadSafety/InstanceVariableInClassMethod: - 'lib/va_profile/contact_information/transaction_response.rb' - 'lib/vic/url_helper.rb' - 'modules/mobile/app/models/mobile/v0/concerns/redis_caching.rb' - -Style/ClassVars: - Exclude: - - 'app/models/preneeds/base.rb' diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index d2a2c5b5d88..9870bf6e144 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -12,7 +12,7 @@ class Base # This class variable is an acceptable use case, because # the values are only set via implicit receiver and I want # subclasses to have shared attributes - @@attributes = {} + @@attributes = {} # rubocop:disable Style/ClassVars class << self # Class method to define a setter & getter for attribute From b5cedbe4c59c019e1da6673f8a0f60767cabdc8b Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:27:10 -0400 Subject: [PATCH 10/21] update the rest of the preneeds models --- app/models/preneeds/base.rb | 7 +++++-- app/models/preneeds/burial_form.rb | 2 +- app/models/preneeds/claimant.rb | 2 +- .../preneeds/currently_buried_person.rb | 2 +- app/models/preneeds/date_range.rb | 2 +- .../preneeds/preneed_attachment_hash.rb | 2 +- app/models/preneeds/race.rb | 2 +- app/models/preneeds/service_record.rb | 2 +- app/models/preneeds/veteran.rb | 2 +- app/models/preneeds/virtus_base.rb | 20 ------------------- 10 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 app/models/preneeds/virtus_base.rb diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 9870bf6e144..42e448f60f6 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -1,5 +1,10 @@ # frozen_string_literal: true +# This will be moved after virtus is removed +module Boolean; end +class TrueClass; include Boolean; end +class FalseClass; include Boolean; end + # Parent class for other Preneeds Burial form related models # Should not be initialized directly # @@ -26,12 +31,10 @@ class << self def attribute(name, klass, default: nil) @@attributes[name] = { type: klass, default: } - # Define a getter method for the attribute define_method(name) do instance_variable_get("@#{name}") || default end - # Define a setter method for the attribute define_method("#{name}=") do |value| value = klass.new(value) if value.is_a?(Hash) diff --git a/app/models/preneeds/burial_form.rb b/app/models/preneeds/burial_form.rb index 0713a1cfc00..3145e25efca 100644 --- a/app/models/preneeds/burial_form.rb +++ b/app/models/preneeds/burial_form.rb @@ -33,7 +33,7 @@ module Preneeds # @!attribute veteran # @return [Preneeds::Veteran] Veteran object. Veteran is the person who is the owner of the benefit. # - class BurialForm < Preneeds::VirtusBase + class BurialForm < Preneeds::Base # Preneeds Burial Form official form id # FORM = '40-10007' diff --git a/app/models/preneeds/claimant.rb b/app/models/preneeds/claimant.rb index fcbaa74aef9..d198874e46b 100644 --- a/app/models/preneeds/claimant.rb +++ b/app/models/preneeds/claimant.rb @@ -22,7 +22,7 @@ module Preneeds # @!attribute address # @return [Preneeds::Address] claimant's address # - class Claimant < Preneeds::VirtusBase + class Claimant < Preneeds::Base attribute :date_of_birth, String attribute :desired_cemetery, String attribute :email, String diff --git a/app/models/preneeds/currently_buried_person.rb b/app/models/preneeds/currently_buried_person.rb index b4fe917c83a..b5e8023ce26 100644 --- a/app/models/preneeds/currently_buried_person.rb +++ b/app/models/preneeds/currently_buried_person.rb @@ -10,7 +10,7 @@ module Preneeds # @!attribute name # @return [Preneeds::FullName] currently buried person's full name # - class CurrentlyBuriedPerson < Preneeds::VirtusBase + class CurrentlyBuriedPerson < Preneeds::Base attribute :cemetery_number, String attribute :name, Preneeds::FullName diff --git a/app/models/preneeds/date_range.rb b/app/models/preneeds/date_range.rb index 104645dd7c6..f1bcbe8790a 100644 --- a/app/models/preneeds/date_range.rb +++ b/app/models/preneeds/date_range.rb @@ -8,7 +8,7 @@ module Preneeds # @!attribute to # @return [String] 'to' date # - class DateRange < Preneeds::VirtusBase + class DateRange < Preneeds::Base attribute :from, String attribute :to, String diff --git a/app/models/preneeds/preneed_attachment_hash.rb b/app/models/preneeds/preneed_attachment_hash.rb index 1ddd297a07e..7cac5fe5d6c 100644 --- a/app/models/preneeds/preneed_attachment_hash.rb +++ b/app/models/preneeds/preneed_attachment_hash.rb @@ -11,7 +11,7 @@ module Preneeds # @!attribute name # @return [String] attachment file name # - class PreneedAttachmentHash < Preneeds::VirtusBase + class PreneedAttachmentHash < Preneeds::Base attribute :confirmation_code, String attribute :attachment_id, String attribute :name, String diff --git a/app/models/preneeds/race.rb b/app/models/preneeds/race.rb index 1388d2209b4..340d287f0aa 100644 --- a/app/models/preneeds/race.rb +++ b/app/models/preneeds/race.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Preneeds - class Race < Preneeds::VirtusBase + class Race < Preneeds::Base ATTRIBUTE_MAPPING = { 'I' => :is_american_indian_or_alaskan_native, 'A' => :is_asian, diff --git a/app/models/preneeds/service_record.rb b/app/models/preneeds/service_record.rb index 89f4f85a39b..75631d82e59 100644 --- a/app/models/preneeds/service_record.rb +++ b/app/models/preneeds/service_record.rb @@ -16,7 +16,7 @@ module Preneeds # @!attribute date_range # @return [Preneeds::DateRange] service date range # - class ServiceRecord < Preneeds::VirtusBase + class ServiceRecord < Preneeds::Base attribute :service_branch, String attribute :discharge_type, String attribute :highest_rank, String diff --git a/app/models/preneeds/veteran.rb b/app/models/preneeds/veteran.rb index 8fb99066903..f898e06846b 100644 --- a/app/models/preneeds/veteran.rb +++ b/app/models/preneeds/veteran.rb @@ -34,7 +34,7 @@ module Preneeds # @!attribute service_records # @return [Array] veteran's service records # - class Veteran < Preneeds::VirtusBase + class Veteran < Preneeds::Base attribute :date_of_birth, String attribute :date_of_death, String attribute :gender, String diff --git a/app/models/preneeds/virtus_base.rb b/app/models/preneeds/virtus_base.rb deleted file mode 100644 index b7284621c9d..00000000000 --- a/app/models/preneeds/virtus_base.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Preneeds - # Parent class for other Preneeds Burial form related models - # Should not be initialized directly - # - class VirtusBase - extend ActiveModel::Naming - include Virtus.model(nullify_blank: true) - - # Override `as_json` - # - # @param options [Hash] - # @see https://github.com/rails/rails/blob/49c613463b758a520a6162e702acc1158fc210ca/activesupport/lib/active_support/core_ext/object/json.rb#L46 - # - def as_json(options = {}) - super(options).deep_transform_keys { |key| key.camelize(:lower) } - end - end -end From 41f653d453b43900f2c041ee6b17d9ea5822479f Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:39:47 -0400 Subject: [PATCH 11/21] fix methods as default issue --- app/models/preneeds/base.rb | 59 +++++++++++++++++++++------ app/models/preneeds/burial_form.rb | 4 +- app/models/preneeds/race.rb | 2 +- app/models/preneeds/service_record.rb | 4 +- app/models/preneeds/veteran.rb | 2 +- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 42e448f60f6..97f3002c393 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -15,45 +15,78 @@ class Base include ActiveModel::Serializers::JSON # This class variable is an acceptable use case, because - # the values are only set via implicit receiver and I want - # subclasses to have shared attributes + # the values are only set via implicit receiver and the + # subclasses should have shared attributes @@attributes = {} # rubocop:disable Style/ClassVars class << self # Class method to define a setter & getter for attribute # this will also coerce a hash to the require class # doesn't currently coerce scalar classes such as string to int + # In the future this could become it's own class e.g., Vets::Model::Attribute # # @param name [Symbol] the name of the attribute # @param klass [Class] the class of the attribute # @param default [String|Integer] the default value of the attribute # - def attribute(name, klass, default: nil) - @@attributes[name] = { type: klass, default: } + def attribute(name, klass, **options) + default = options[:default] + array = options[:array] || false + @@attributes[name] = { type: klass, default:, array: } + + define_getter(name, default) + define_setter(name, klass, array) + end + + def attribute_set + @@attributes.keys + end + + private + + def define_getter(name, default) define_method(name) do - instance_variable_get("@#{name}") || default + instance_variable_get("@#{name}") || begin + return nil unless defined?(default) + + if default.is_a?(Symbol) && respond_to?(default) + send(default) + else + default + end + end end + end + def define_setter(name, klass, array) define_method("#{name}=") do |value| + if array + unless value.is_a?(Array) + raise TypeError, "#{name} must be an Array" + end + + value = value.map do |item| + item.is_a?(Hash) ? klass.new(item) : item + end + + unless value.all? { |item| item.is_a?(klass) } + raise TypeError, "All elements of #{name} must be of type #{klass}" + end + end + value = klass.new(value) if value.is_a?(Hash) - if value.is_a?(klass) || value.nil? + if (array && value.is_a?(Array)) || value.is_a?(klass) || value.nil? instance_variable_set("@#{name}", value) else raise TypeError, "#{name} must be a #{klass}" end end end - - def attribute_set - @@attributes.keys - end end - # Acts as ActiveRecord::Base#attributes which is needed - # for serialization - # + # Acts as ActiveRecord::Base#attributes which is needed for serialization def attributes nested_attributes(instance_values) end diff --git a/app/models/preneeds/burial_form.rb b/app/models/preneeds/burial_form.rb index 3145e25efca..122d87ad472 100644 --- a/app/models/preneeds/burial_form.rb +++ b/app/models/preneeds/burial_form.rb @@ -39,7 +39,7 @@ class BurialForm < Preneeds::Base FORM = '40-10007' attribute :application_status, String, default: '' - attribute :preneed_attachments, Array[PreneedAttachmentHash] + attribute :preneed_attachments, PreneedAttachmentHash, array: true attribute :has_currently_buried, String attribute :sending_application, String, default: 'vets.gov' attribute :sending_code, String, default: '' @@ -47,7 +47,7 @@ class BurialForm < Preneeds::Base attribute :tracking_number, String, default: :generate_tracking_number attribute :applicant, Preneeds::Applicant attribute :claimant, Preneeds::Claimant - attribute :currently_buried_persons, Array[Preneeds::CurrentlyBuriedPerson] + attribute :currently_buried_persons, Preneeds::CurrentlyBuriedPerson, array: true attribute :veteran, Preneeds::Veteran # keeping this name because it matches the previous attribute diff --git a/app/models/preneeds/race.rb b/app/models/preneeds/race.rb index 340d287f0aa..0c9d82720ce 100644 --- a/app/models/preneeds/race.rb +++ b/app/models/preneeds/race.rb @@ -13,7 +13,7 @@ class Race < Preneeds::Base }.freeze ATTRIBUTE_MAPPING.each_value do |attr| - attribute(attr, Boolean) + attribute(attr, Boolean, default: false) end def as_eoas diff --git a/app/models/preneeds/service_record.rb b/app/models/preneeds/service_record.rb index 75631d82e59..04aa252c762 100644 --- a/app/models/preneeds/service_record.rb +++ b/app/models/preneeds/service_record.rb @@ -29,8 +29,8 @@ class ServiceRecord < Preneeds::Base def as_eoas hash = { branchOfService: service_branch, dischargeType: discharge_type, - enteredOnDutyDate: date_range.try(:[], :from), highestRank: highest_rank, - nationalGuardState: national_guard_state, releaseFromDutyDate: date_range.try(:[], :to) + enteredOnDutyDate: date_range.try(:from), highestRank: highest_rank, + nationalGuardState: national_guard_state, releaseFromDutyDate: date_range.try(:to) } %i[ diff --git a/app/models/preneeds/veteran.rb b/app/models/preneeds/veteran.rb index f898e06846b..5ae0d46c073 100644 --- a/app/models/preneeds/veteran.rb +++ b/app/models/preneeds/veteran.rb @@ -50,7 +50,7 @@ class Veteran < Preneeds::Base attribute :address, Preneeds::Address attribute :current_name, Preneeds::FullName attribute :service_name, Preneeds::FullName - attribute :service_records, Array[Preneeds::ServiceRecord] + attribute :service_records, Preneeds::ServiceRecord, array: true # (see Preneeds::BurialForm#as_eoas) # From c7501c26350ac5d54c99d3db996e504cfa02298c Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:25:35 -0400 Subject: [PATCH 12/21] linting --- app/models/preneeds/base.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 97f3002c393..7c523ae5372 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -62,9 +62,7 @@ def define_getter(name, default) def define_setter(name, klass, array) define_method("#{name}=") do |value| if array - unless value.is_a?(Array) - raise TypeError, "#{name} must be an Array" - end + raise TypeError, "#{name} must be an Array" unless value.is_a?(Array) value = value.map do |item| item.is_a?(Hash) ? klass.new(item) : item From 258d772d74be1cc86648f68441718fc50be3288c Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:04:40 -0400 Subject: [PATCH 13/21] cast strings to boolean --- app/models/preneeds/base.rb | 6 +++++- spec/factories/preneeds/veterans.rb | 2 +- spec/requests/v0/preneeds/burial_forms_spec.rb | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 7c523ae5372..62998d982f3 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -11,7 +11,7 @@ class FalseClass; include Boolean; end module Preneeds class Base extend ActiveModel::Naming - include ActiveModel::Model + # include ActiveModel::Model include ActiveModel::Serializers::JSON # This class variable is an acceptable use case, because @@ -73,6 +73,10 @@ def define_setter(name, klass, array) end end + if klass == Boolean + value = ActiveModel::Type::Boolean.new.cast(value) + end + value = klass.new(value) if value.is_a?(Hash) if (array && value.is_a?(Array)) || value.is_a?(klass) || value.nil? diff --git a/spec/factories/preneeds/veterans.rb b/spec/factories/preneeds/veterans.rb index c1bb3eedbe1..4c575bd6616 100644 --- a/spec/factories/preneeds/veterans.rb +++ b/spec/factories/preneeds/veterans.rb @@ -11,7 +11,7 @@ place_of_birth { 'Brooklyn, NY' } ssn { '123-45-6789' } va_claim_number { '23456789' } - military_status { 'A' } + # military_status { 'A' } race { attributes_for(:race) } current_name { attributes_for :full_name } diff --git a/spec/requests/v0/preneeds/burial_forms_spec.rb b/spec/requests/v0/preneeds/burial_forms_spec.rb index d14318a28c1..9da5f6ec96e 100644 --- a/spec/requests/v0/preneeds/burial_forms_spec.rb +++ b/spec/requests/v0/preneeds/burial_forms_spec.rb @@ -16,7 +16,7 @@ let(:submission_record) { OpenStruct.new(application_uuid: 'UUID') } let(:form) do - Preneeds::BurialForm.new(params).tap do |f| + Preneeds::BurialForm.new(params[:application]).tap do |f| f.claimant = Preneeds::Claimant.new( email: 'foo@foo.com', name: Preneeds::FullName.new( From ae745a3a40d5cc63814fc39b84baa93690163b0b Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:55:15 -0400 Subject: [PATCH 14/21] switch back to class instance methods --- app/models/preneeds/base.rb | 34 ++++++++++++++++++++--------- spec/factories/preneeds/veterans.rb | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 62998d982f3..23073a1cef1 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -11,15 +11,23 @@ class FalseClass; include Boolean; end module Preneeds class Base extend ActiveModel::Naming - # include ActiveModel::Model + include ActiveModel::Model include ActiveModel::Serializers::JSON - # This class variable is an acceptable use case, because - # the values are only set via implicit receiver and the - # subclasses should have shared attributes - @@attributes = {} # rubocop:disable Style/ClassVars + @attributes = Concurrent::Map.new class << self + + # class variable attributes won't work so this is + # the only way for it to work. Thread safety shouldn't + # matter because @attributes are the same across all thread + # they are set by the class + # rubocop:disable ThreadSafety/InstanceVariableInClassMethod + def attributes + @attributes ||= {} + end + # rubocop:enabled ThreadSafety/InstanceVariableInClassMethod + # Class method to define a setter & getter for attribute # this will also coerce a hash to the require class # doesn't currently coerce scalar classes such as string to int @@ -33,14 +41,14 @@ def attribute(name, klass, **options) default = options[:default] array = options[:array] || false - @@attributes[name] = { type: klass, default:, array: } + attributes[name] = { type: klass, default:, array: } define_getter(name, default) define_setter(name, klass, array) end def attribute_set - @@attributes.keys + attributes.keys end private @@ -73,9 +81,7 @@ def define_setter(name, klass, array) end end - if klass == Boolean - value = ActiveModel::Type::Boolean.new.cast(value) - end + value = ActiveModel::Type::Boolean.new.cast(value) if klass == Boolean value = klass.new(value) if value.is_a?(Hash) @@ -88,6 +94,14 @@ def define_setter(name, klass, array) end end + def initialize(params = {}) + super + # Ensure all attributes have a defined value (default to nil) + self.class.attribute_set.each do |attr_name| + instance_variable_set("@#{attr_name}", nil) unless instance_variable_defined?("@#{attr_name}") + end + end + # Acts as ActiveRecord::Base#attributes which is needed for serialization def attributes nested_attributes(instance_values) diff --git a/spec/factories/preneeds/veterans.rb b/spec/factories/preneeds/veterans.rb index 4c575bd6616..c1bb3eedbe1 100644 --- a/spec/factories/preneeds/veterans.rb +++ b/spec/factories/preneeds/veterans.rb @@ -11,7 +11,7 @@ place_of_birth { 'Brooklyn, NY' } ssn { '123-45-6789' } va_claim_number { '23456789' } - # military_status { 'A' } + military_status { 'A' } race { attributes_for(:race) } current_name { attributes_for :full_name } From 8faf8312b90573725a00c0b3b05c0513319b5126 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:00:56 -0400 Subject: [PATCH 15/21] linting --- app/models/preneeds/base.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 23073a1cef1..4c426c03632 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -14,19 +14,18 @@ class Base include ActiveModel::Model include ActiveModel::Serializers::JSON - @attributes = Concurrent::Map.new + @attributes = {}.freeze class << self - # class variable attributes won't work so this is # the only way for it to work. Thread safety shouldn't - # matter because @attributes are the same across all thread - # they are set by the class + # matter because @attributes is the same across all thread + # they are set by the class. # rubocop:disable ThreadSafety/InstanceVariableInClassMethod def attributes @attributes ||= {} end - # rubocop:enabled ThreadSafety/InstanceVariableInClassMethod + # rubocop:enable ThreadSafety/InstanceVariableInClassMethod # Class method to define a setter & getter for attribute # this will also coerce a hash to the require class From b9cbc6a84a4b0d37ef816f109d23eaf55db18d34 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:54:25 -0400 Subject: [PATCH 16/21] move boolean to core_extensions --- app/models/preneeds/base.rb | 7 ------- lib/core_extensions/boolean.rb | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) create mode 100644 lib/core_extensions/boolean.rb diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 4c426c03632..0c54de070ab 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -1,13 +1,6 @@ # frozen_string_literal: true - -# This will be moved after virtus is removed -module Boolean; end -class TrueClass; include Boolean; end -class FalseClass; include Boolean; end - # Parent class for other Preneeds Burial form related models # Should not be initialized directly -# module Preneeds class Base extend ActiveModel::Naming diff --git a/lib/core_extensions/boolean.rb b/lib/core_extensions/boolean.rb new file mode 100644 index 00000000000..1be6e11fe9c --- /dev/null +++ b/lib/core_extensions/boolean.rb @@ -0,0 +1,3 @@ +module Boolean; end +class TrueClass; include Boolean; end +class FalseClass; include Boolean; end From bce565a50c459e603c58448f735f3632e4664db3 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:56:22 -0400 Subject: [PATCH 17/21] fix spacing of comments --- app/models/preneeds/base.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index 0c54de070ab..c90394ad54d 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Parent class for other Preneeds Burial form related models # Should not be initialized directly module Preneeds From bd8a0c53859ef361c4d7197b9a348f4bcb967eba Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:59:32 -0400 Subject: [PATCH 18/21] linting --- .github/CODEOWNERS | 1 + lib/core_extensions/boolean.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index dd8bb206997..275dcfebf57 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -862,6 +862,7 @@ lib/common/pdf_helpers.rb @department-of-veterans-affairs/benefits-decision-revi lib/common/models @department-of-veterans-affairs/backend-review-group lib/common/virus_scan.rb @department-of-veterans-affairs/backend-review-group lib/common @department-of-veterans-affairs/backend-review-group +lib/core_extensions @department-of-veterans-affairs/backend-review-group lib/debt_management_center @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group lib/decision_review @department-of-veterans-affairs/benefits-decision-reviews-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group lib/decision_review_v1 @department-of-veterans-affairs/benefits-decision-reviews-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group diff --git a/lib/core_extensions/boolean.rb b/lib/core_extensions/boolean.rb index 1be6e11fe9c..79d52fdd2c9 100644 --- a/lib/core_extensions/boolean.rb +++ b/lib/core_extensions/boolean.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Boolean; end class TrueClass; include Boolean; end class FalseClass; include Boolean; end From 587c138aa140a975b91abe050928e719d48e78e9 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:19:02 -0400 Subject: [PATCH 19/21] add core_extensions initializer --- config/initializers/core_extensions.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/initializers/core_extensions.rb diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb new file mode 100644 index 00000000000..535700b1ccc --- /dev/null +++ b/config/initializers/core_extensions.rb @@ -0,0 +1 @@ +Dir[File.join(Rails.root, "lib", "core_extensions", "*.rb")].each {|l| require l } From a3615aa25851edd1383ab3bcb92f39e6de022a51 Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:25:39 -0400 Subject: [PATCH 20/21] linting --- .github/CODEOWNERS | 1 + config/initializers/core_extensions.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 275dcfebf57..cebabc16864 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -743,6 +743,7 @@ config/initializers/clamav.rb @department-of-veterans-affairs/va-api-engineers @ config/initializers/combine_pdf_log_patch.rb @department-of-veterans-affairs/backend-review-group config/initializers/config.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group config/initializers/cookie_rotation.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +config/initializers/core_extensions.rb @department-of-veterans-affairs/backend-review-group config/initializers/covid_vaccine_facilities.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/long-covid config/initializers/datadog.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group config/initializers/date_formats.rb @department-of-veterans-affairs/octo-identity diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb index 535700b1ccc..25e0194280d 100644 --- a/config/initializers/core_extensions.rb +++ b/config/initializers/core_extensions.rb @@ -1 +1,3 @@ -Dir[File.join(Rails.root, "lib", "core_extensions", "*.rb")].each {|l| require l } +# frozen_string_literal: true + +Dir[Rails.root.join('lib', 'core_extensions', '*.rb').to_s].each { |l| require l } From 72036413313d7fbb2409bdcea6439492f49658af Mon Sep 17 00:00:00 2001 From: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:54:03 -0400 Subject: [PATCH 21/21] remove core extension until common base is updated --- app/models/preneeds/base.rb | 6 ++++++ config/initializers/core_extensions.rb | 3 --- lib/core_extensions/boolean.rb | 5 ----- 3 files changed, 6 insertions(+), 8 deletions(-) delete mode 100644 config/initializers/core_extensions.rb delete mode 100644 lib/core_extensions/boolean.rb diff --git a/app/models/preneeds/base.rb b/app/models/preneeds/base.rb index c90394ad54d..4c426c03632 100644 --- a/app/models/preneeds/base.rb +++ b/app/models/preneeds/base.rb @@ -1,7 +1,13 @@ # frozen_string_literal: true +# This will be moved after virtus is removed +module Boolean; end +class TrueClass; include Boolean; end +class FalseClass; include Boolean; end + # Parent class for other Preneeds Burial form related models # Should not be initialized directly +# module Preneeds class Base extend ActiveModel::Naming diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb deleted file mode 100644 index 25e0194280d..00000000000 --- a/config/initializers/core_extensions.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -Dir[Rails.root.join('lib', 'core_extensions', '*.rb').to_s].each { |l| require l } diff --git a/lib/core_extensions/boolean.rb b/lib/core_extensions/boolean.rb deleted file mode 100644 index 79d52fdd2c9..00000000000 --- a/lib/core_extensions/boolean.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -module Boolean; end -class TrueClass; include Boolean; end -class FalseClass; include Boolean; end