This repository has been archived by the owner on Sep 25, 2020. It is now read-only.
Add preferential_settings, getter/setters, and optional encryption #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a class method to all ActiveRecord::Base models that allows you to set "preferential settings".
Backstory:
We find it useful to be able to encrypt settings on our side when necessary. We also use this to set default values for settings after_create. In addition, we give each setting its own getter and setter method right on our model.
For example:
Now whenever I create a new SomeModel object, I get the following
I've also added a
settings=
method, so you can do the following:You can still use settings where the key is not in preferential_settings, they just don't get accessor methods, so they're used as you normally would before these changes.
While you can also write validations for the new accessor methods provided by preferential settings, there is not yet any code around enforcing them. This means that if I did the following:
The validations would run, but not be enforced. An example:
I hope to add code around this in an upcoming PR