Gemfiles are basically your only code-sharing option in Ruby. One good thing about Bundler is that it’s smart enough to allow reading gems from subfolders of a larger project, so you wouldn’t necessarily need to split it out of the project it belongs to.
# Gemfile
path "schema" do
gem "my_service-schema"
end
You could then define the schema subfolder with its own gemspec, and then any project that needs it would do:
I was interested in the ability to initialize schemas, for example, from ast. It would be very convenient.
Another disadvantage of the approach through the gem is that let’s say I have a schema that I put in the gem. I can use this scheme on my other service. But I got a case when from this scheme I want to make my own custom and not one. Every time to go to the gem and add the scheme by hand is a bad option for me.
Therefore, I wanted to know if you can have some solution for this so that you can somehow dump the circuit, and then make a load.
I agree, the AST-Visitor approach the dry-rb libraries use is a powerful pattern, and there is a lot of untapped potential for code generation.
It would be really interesting to generate dry-types from RBI definitions, for instance. Or schemas from API definitions like Swagger or JSON Schema.
I think the primary reason why this hasn’t been done yet is it’s a lot of work. If I ever get around to building something generally useful like this, I’ll post about it.
Yes, it’s my dream to have this work out of the box
In the vastness of github, I found a gem that can get the metadata from the schema. (This is interesting, by the way) But the problem is again that having a schema in json format, conditionally, I cannot initialize it without some magic.