Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Vets::Model with value "coercion" functionality #19979

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

stevenjcumming
Copy link
Contributor

@stevenjcumming stevenjcumming commented Dec 20, 2024

It looks like a lot but there's it's more repetition

Summary

  • In order to replace Virtus and Common::Base with Vets::Model the values will need to be coerced to the intended class

Example:

class ExampleModel
   attribute :id, Integer
end

model = ExampleModel.new(id: '123') 
model.id 
#=> 123
  • Based on 3 minutes of googling, cast seems to be a better word than coerce, so I've stuck with that
  • There are 5 types of types: Primitive, Array, Hash, Object, and Custom Primitive (eg UTCTime)
    • All types perform the casting in the same way for Vets::Attributes::Value
    • A type cast an input value to the desired class
  • This is a pseudo-factory pattern (hence the repetition)
  • Primitives rely on ActiveModel::Type for the casting logic
    • except for Time which defaulted to 2000-01-01 for the date and I didn't like that

Related issue(s)

Testing done

  • Add new specs for each class
  • Updated value spec

Acceptance criteria

  • Values are coercible
  • A list of coercible values is provided in vets as a readme.md types.rb as a comment

Requested Feedback

  • I couldn't finding any logic to match with what's coercible and what's not, other than use of Axiom::Types that implied the use of the standard casting (.to_s, .to_i, etc.). Sticking with my plan to use ActiveModel as the inspiration for Vets::Model, I chose to use ActiveModel::Type casting.

For the Primitive, if the logic is flawed, I can switch to the standard casting (.to_s)

Copy link

github-actions bot commented Dec 20, 2024

1 Error
🚫 This PR changes 936 LoC (not counting whitespace/newlines).

In order to ensure each PR receives the proper attention it deserves, those exceeding
500 will not be reviewed, nor will they be allowed to merge. Please break this PR up into
smaller ones.

If you have reason to believe that this PR should be granted an exception, please see the
Submitting pull requests for approval - FAQ.

File Summary

Files

  • lib/vets/attributes/value.rb (+14/-32)

  • lib/vets/model.rb (+0/-0)

  • lib/vets/type/array.rb (+30/-0)

  • lib/vets/type/base.rb (+16/-0)

  • lib/vets/type/date_time_string.rb (+16/-0)

  • lib/vets/type/hash.rb (+18/-0)

  • lib/vets/type/http_date.rb (+16/-0)

  • lib/vets/type/iso8601_time.rb (+16/-0)

  • lib/vets/type/object.rb (+17/-0)

  • lib/vets/type/primitive.rb (+30/-0)

  • lib/vets/type/titlecase_string.rb (+14/-0)

  • lib/vets/type/utc_time.rb (+16/-0)

  • lib/vets/types.rb (+10/-0)

  • modules/avs/app/models/avs/v0/after_visit_summary.rb (+5/-5)

  • spec/lib/vets/attributes/value_spec.rb (+97/-105)

  • spec/lib/vets/type/array_spec.rb (+131/-0)

  • spec/lib/vets/type/base_spec.rb (+19/-0)

  • spec/lib/vets/type/date_time_string_spec.rb (+28/-0)

  • spec/lib/vets/type/hash_spec.rb (+27/-0)

  • spec/lib/vets/type/http_date_spec.rb (+42/-0)

  • spec/lib/vets/type/iso8601_time_spec.rb (+28/-0)

  • spec/lib/vets/type/object_spec.rb (+46/-0)

  • spec/lib/vets/type/primitive_spec.rb (+85/-0)

  • spec/lib/vets/type/titlecase_string_spec.rb (+38/-0)

  • spec/lib/vets/type/utc_time_spec.rb (+35/-0)

    Note: We exclude files matching the following when considering PR size:

    *.csv, *.json, *.tsv, *.txt, *.md, Gemfile.lock, app/swagger, modules/mobile/docs, spec/fixtures/, spec/support/vcr_cassettes/, modules/mobile/spec/support/vcr_cassettes/, db/seeds, modules/vaos/app/docs, modules/meb_api/app/docs, modules/appeals_api/app/swagger/, *.bru, *.pdf
    

Big PRs are difficult to review, often become stale, and cause delays.

Generated by 🚫 Danger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants