Skip to content

Commit

Permalink
Post-PR cleanup
Browse files Browse the repository at this point in the history
- removed some trailing whitespace
- made the list of classes in the README agree with the list in the warning
- tweaked warning verbiage
  • Loading branch information
geeksam committed Jul 29, 2022
1 parent e6ed78b commit e595d13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,16 @@ which uses [Psych.safe_load](https://www.rubydoc.info/stdlib/psych/Psych.safe_lo
LabTech requires permitting the following classes using
[config.active_record.yaml_column_permitted_classes](https://guides.rubyonrails.org/configuring.html#config-active-record-yaml-column-permitted-classes):

- `Symbol`
- `Time`
- `ActiveSupport::Duration`
- `ActiveSupport::TimeWithZone`
- `ActiveSupport::TimeZone`
- `Symbol`
- `Time`

*Note: this list is almost certainly incomplete!*

If you discover new ones, please submit an issue or PR. (There's also a list
in ./lib/lab_tech/engine.rb that should be considered canonical.)

## Contributing

Expand Down
19 changes: 15 additions & 4 deletions lib/lab_tech/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ class Engine < ::Rails::Engine
config.generators.api_only = true

config.after_initialize do
# NOTE: this list also exists in the README; please try to keep them in sync.
required_serializable_classes = [
ActiveSupport::Duration,
ActiveSupport::TimeWithZone,
ActiveSupport::TimeZone,
Time,
Symbol,
Time,
]

missing_classes = required_serializable_classes - Rails.configuration.active_record.yaml_column_permitted_classes

if missing_classes.any?
puts "Please add #{missing_classes.join(', ')} to your Rails.configuration.active_record.yaml_column_permitted_classes.".red
puts "LabTech will break your application horribly unless you do.".red
puts <<~EOF.red
Please add the following classes to your
Rails.configuration.active_record.yaml_column_permitted_classes:
#{ missing_classes.map { |klass| " - #{klass}" }.join('\n') }
Because LabTech uses ActiveRecord's `serialize` to save experimental
results to the database, running experiments is likely to break your
application horribly without this configuration.
EOF
end
end
end
Expand Down

0 comments on commit e595d13

Please sign in to comment.