You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm open to this, but I want to sniff out exactly the use case here. I see two ways this can go: either in the form definition, you declare a model that this Form can be translated into:
Or, we could use some magic with method_missing to try to inflect the class you intend to create.
classPersonForm < Slayer::Formattribute:name,Stringendform=PersonForm.new(name: 'Joe')form.to_person# => inflect Person from `to_person`form.to_contact# => inflect Contact fform.to_car_dealership# => inflect CarDealership from `to_person`# The above could all shorthand to a call to a #to_model method, like belowform.to_model(Namespaced::Person)# => bypass inflection, attempt to convert to Namespaced::Person
The second version here is more flexible, since it lets us convert a Form into any model, and any model that has a name attribute will get the value from the Form, but it also is more "magic," and as such inherently less trustworthy
From here: apsislabs/slayer#50
It should be easy to write a class method that you can call to generate a
to_<model>
method.The text was updated successfully, but these errors were encountered: