madeintandem / jsonb_accessor

Adds typed jsonb backed fields to your ActiveRecord models.
MIT License
1.11k stars 93 forks source link

Prefix / Suffix feature request #173

Open borisrorsvort opened 1 year ago

borisrorsvort commented 1 year ago

Would it be possible to introduce prefix/suffix options for attribute names in jsonb_accessor? This would allow developers to write more concise and readable code, particularly when dealing with multiple attributes.

For example, instead of writing:

jsonb_accessor :voting_options,
               voting_options_type:        [:string, { default: VOTING_OPTIONS_TYPES[0], store_key: :type }],
               voting_options_min_votes:   [:integer, { store_key: :min_votes }],
               ...

we could have:

jsonb_accessor :voting_options,
               type:        [:string, { default: VOTING_OPTIONS_TYPES[0], suffix: true }],
               ...

This addition would not only streamline code but also maintain readability and ease of maintenance.

I understand the complexities involved in maintaining an open-source project and adding new features. If this suggestion aligns with your vision for the gem, I'd be delighted to see it implemented.

haffla commented 1 year ago

Hey @borisrorsvort,

thanks. Sure I would welcome such addition to the code if it only changes the name of the getter and setter methods.

Your above example would generate

instead of

correct?

borisrorsvort commented 1 year ago

yes! but it would still be stored as type inside the json on the column voting_options.