activerecord-typedstore icon indicating copy to clipboard operation
activerecord-typedstore copied to clipboard

Namespaces for accessors

Open davidmccoy opened this issue 6 years ago • 2 comments

I'm looking to use multiple jsonb columns on the same model. However, it is possible some of those columns will share the same keys, which can lead to problems when using accessors.

Is it currently possible to create namespaces for accessors? For example, something like:

class NotificationSettings < ApplicationRecord
  typed_store :email do |s|
    namespace :email 
    s.boolean :enabled, default: false, null: false
    ....
  end

  typed_store :push do |s| 
    namespace :push  
    s.boolean :enabled, default: false, null: false
    ....
  end

  typed_store :sms do |s| 
    namespace :sms  
    s.boolean :enabled, default: false, null: false
    ....
  end
end

So that I could access each enabled setting with an accessor? Like NoficiationSettings.email.enabled?.

davidmccoy avatar Nov 13 '18 18:11 davidmccoy

@davidmccoy Ever find a solution for this?

antarr avatar Jun 18 '21 02:06 antarr

@antarr Not with this gem, I just went with straight jsonb.

davidmccoy avatar Jun 18 '21 03:06 davidmccoy