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

RFC: Organise Attribute Information for Trainees #4336

Open
adamjcolvin opened this issue May 30, 2024 · 0 comments
Open

RFC: Organise Attribute Information for Trainees #4336

adamjcolvin opened this issue May 30, 2024 · 0 comments
Labels
refactor Code changes that don't affect any functionality, but make changing the code easier in the future.

Comments

@adamjcolvin
Copy link
Contributor

In our trainee_attributes class, we have a long list of attributes and metadata for them split across multiple constants, and repeated in several places throughout the file.

What if we move this information out into a YAML file or something and organise it more like this:

first_names:
  {
    required: true,
    nested: false,
    internal: false,
    type: "string",
    options: {
      default: "..."
    },
  }
date_of_birth:
  { 
    required: true, 
    nested: false, 
    internal: false, 
    type: "date", 
    options: {} 
}

We could then still use the constants we have in the attributes class, but make them much more concise:

ATTRIBUTES_PATH = File.join(__dir__, 'trainee_attributes.yml')
ATTRIBUTES = YAML.load_file(ATTRIBUTES_PATH).deep_symbolize_keys
REQUIRED_ATTRIBUTES = ATTRIBUTES.select { |_, config| config[:required] }.keys
INTERNAL_ATTRIBUTES = ATTRIBUTES.select { |_, config| config[:internal] }.keys
NESTED_ATTRIBUTES = ATTRIBUTES.select { |_, config| config[:nested] }.keys

That would mean we can keep the attributes class more focused on the validation logic, assigning attributes and that sort of thing, rather than housing all this data. It also means we can add new attributes, and change the metadata just by updating the yaml file.

If we like the pattern, we could also apply it to the other attribute classes.

@adamjcolvin adamjcolvin added the refactor Code changes that don't affect any functionality, but make changing the code easier in the future. label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code changes that don't affect any functionality, but make changing the code easier in the future.
Projects
None yet
Development

No branches or pull requests

1 participant