byroot / activerecord-typedstore

ActiveRecord::Store but with type definition
MIT License
437 stars 57 forks source link

Inline syntax #90

Closed Adeynack closed 2 years ago

Adeynack commented 2 years ago

New Features in This PR

Inline Syntax

It's important to me and my colleague that the stored attribute definition be kept as much as possible a one-liner, as it would be with a basic untyped Rails stored attributes approach. To achieve this, I made available a one-liner DSL approach, where all of the information can be compacted in one call, without passing a block (see README for and example).

StrippedCoder

Another requirement we have is that attributes that are empty or nil should not be included at all in the hash being persisted (in our case: PostgreSQL JSONB field). To achieve that, I made the following modifications:

Adeynack commented 2 years ago

I already have a question though. I did in my fork activate the GitHub CI, since there is a workflow configured in the code. However, even on a clean slate (creating a PR with no modification yet), those tests are not working. Is there a plan to fix them? For the records: rspec runs fine, but I haven't try with actual databases running (I was leaning on the CI to do that).

Adeynack commented 2 years ago

I'm wondering is there any benefit by writing the definition to be one line?

Simply to keep those definitions as concise as possible. That was one of our requirement for choosing a library to achieve typed stores. This one had all features we wanted, except this one-liner-DSL. Instead of recoding things from scratch (which we actually started to before finding this GEM), we thought we'd contribute.

If the feature is deemed unnecessary, I will try to work on a "companion GEM" depending on this one, allowing this one-line-DSL. However, it won't be as pretty at usage time as this integrated proposal.

rafaelfranca commented 2 years ago

Thank you for the pull request but I don't think this feature justify all this complexity. It should not be hard for you do define this inline syntax in your application though.

Adeynack commented 2 years ago

Nope. Not at all. That's how it actually started. Thought it would make a good contribution.

Thanks again for that GEM and keep up the good work!