I'm trying the new dependency injection Ruby stuff. I've made a new app from the template. I'm trying to have this app display a contact form and record responses for later action. This should be trivial enough, right?
My understanding based on trying to read through the documentation scattered across nine different sub-gems, Slideshare posts titled "meet rom-rb", old blog posts announcing
dry-system, the Icelab blog post "Effective Ruby dependency injection at scale" and the
Berg application source. These disparate documents are really hard to integrate into one idea of how things work, but I haven't found a single document that tells me what I need to know.
What I think I know tells me I should go something like:
- generate the app using dry-web-roda because otherwise you will be in dependency-manager-setup-hell forever
- throw together a few migrations
- there's a rake task to make the migration file
- the API docs for this live under the gem 'Sequel'
apps/main/web/routes/contact with a
get and a
apps/main/lib/main/views/contact/show.rb to show the form
- all it has is
config.template = "contact/show" because you're just copying from
apps/main/web/templates/contact/show.html.slim to go with it
- the thing you need to make the form work is a line
== csrf_tag (which is defined in some view context class. do not use a bare
csrf_tag, that'll be interpreted like a
<csrf_tag/>. welcome to Slim.)
apps/main/lib/main/views/contact/thanks.rb to show the "thank you" message after the form. (not very RESTful but hey it's not really meant to be today.)
Project::Operations::Contact to do the work of handling the form
- it inherits from
Project::Operation which was autogenerated
- it lives at
lib/project/operations/contact.rb I guess??!? i have no validation this works
- first draft version will access a repo directly to persist an operation to the database
- not 100% sure where to put this yet but expect it'll be
lib/project/repo/blahblah inheriting from
Project::Repository[:blahblah] – much like ROM docs on repositories – and I'll inject it with
- Access the operation in the route
- to access it do... what?!?!?
self.class["operations.contact"]??!? that's totally not working
- later, use
operation.call to invoke it
- (later, in the distant future, clean it all up, use the initial contact to initiate a crazy CRMy workflow that will actually benefit from properly structured concerns.)
self.class["operations.contact"] seems to be the way to get at things that are registered, there is nothing registered with the key
"operations.contact" and all I get is errors which I have no idea how to debug, because I can't find documentation or a working example anywhere. (Also, I've no idea if the repo works.)
How am I meant to structure my app with these concerns?
How do I debug the case where something is not loading?