I'll start with the general idea:
- My application has validations for various models, but these validations exist across multiple models. So I'm working on making a central module/class that handles validations for multiple models to reduce redundancies. Let's call this class "Validator" and call its method "invalid?"
- We also built a gem for the company to import customer records via Excel spreadsheets -- let's call this gem "Importer". Now we want access to our applications Validator class and its methods from within the gem. That way we can send a hash containing the attributes to validate and their respective methods to call within the application. So for example the gem receives a new object to create, but sees that it should validate ":start_date" and "end_date" (receiving these values from the application itself), but only if the object has these attributes.
- When receiving a method in the Importer gem like: Validator.invalid? the Importer gem cannot find the application's context.
I'm not new to Rails but I've never had to call application methods from a gem. I think I have to do something in the Railties class to load it in, but I have no idea how/what I have to do.
If anyone has any experience in this, I'd really appreciate the help
Thanks in advance.