G5 / storext

Add type-casting and other features on top of ActiveRecord::Store.store_accessor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default value based on another value?

mscoutermarsh opened this issue · comments

Hey,

Had this idea, not sure if currently possible.

Would be nice if we could set a default to be based on another existing value.

Use Case:

  • I want to add a new "notification setting"
  • Can base this settings default on another already existing setting.
  • This way, the setting is "smart" and auto sets itself based on what user has done in the past.

Such as:

store_attributes :email_settings do
  subscribed_to_email Boolean, default: true
  subscribe_to_comment_notification_email Boolean, default: subscribed_to_email
end

Is it possible today?

If not - any interest in having this ability in the gem? (I can work on it)

@mscoutermarsh this might already work, because Virtus ;)

Can you try:

store_attributes :email_settings do
  subscribed_to_email Boolean, default: true
  subscribe_to_comment_notification_email Boolean, lazy: true, default: :subscribed_to_email
end

WORKS! Awesome @ramontayag 😄