Session
Off the Rails: Validating non-model classes with…ActiveModel?
Have you ever wished you could run Rails validators to check that a Hash, Struct or Data instance is properly formatted? Have you ever wanted to be able to compose complex validation logic on the fly rather than registering them at a class level with complicated conditionals? Did you ever have a use case for a single, generic validation and thought it’d be overkill to create a new ActiveModel class?
In this talk, we'll explore how to build a single class that’ll accept almost any kind of argument and let you register and run both built-in and custom validations against that argument’s key/value pairs and methods. Through test-driven development and examining the source code for ActiveModel validations and ActiveSupport callbacks, we’ll gradually build a robust solution to support custom and built-in validators and their various options like `if` and `allow_blank`.
Whether you want to validate a JSON field in a model, ensure that an incoming API request is properly formatted, check for valid events in an event-sourced application or run a validator against a class from a third-party library without monkey-patching, this talk will help you use some of Rails’ most classic features in a new and powerful way.

Andy Andrea
Lead Software Developer at Panorama Education
Durham, North Carolina, United States
Links
Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.
Jump to top