module AssociateJsonb::WithStoreAttribute::ClassMethods

Public Instance Methods

add_store_column_attribute_name(name, store, key, cast_opts) click to toggle source
# File lib/associate_jsonb/with_store_attribute.rb, line 74
def add_store_column_attribute_name(name, store, key, cast_opts)
  store_column_attribute_tracker.synchronize do
    store_column_attribute_tracker.add_name(name, store, key, cast_opts)
  end
end
arel_table() click to toggle source
Calls superclass method
# File lib/associate_jsonb/with_store_attribute.rb, line 51
def arel_table
  super.with_store_tracker(store_column_attribute_tracker)
end
data_column_attribute(*args, **opts) click to toggle source
# File lib/associate_jsonb/with_store_attribute.rb, line 97
def data_column_attribute(*args, **opts)
  store_column_attribute :data, *args, **opts
end
inherited(child) click to toggle source
Calls superclass method
# File lib/associate_jsonb/with_store_attribute.rb, line 46
def inherited(child)
  child.initialize_store_column_attribute_tracker
  super
end
initialize_store_column_attribute_tracker() click to toggle source
# File lib/associate_jsonb/with_store_attribute.rb, line 55
def initialize_store_column_attribute_tracker
  @store_column_attribute_tracker = const_set(:StoreColumnAttributeTracker, StoreColumnAttributeTracker.new)
  private_constant :StoreColumnAttributeTracker

  store_column_attribute_tracker
end
is_store_column_attribute?(name) click to toggle source
# File lib/associate_jsonb/with_store_attribute.rb, line 80
def is_store_column_attribute?(name)
  store_column_attribute_tracker.synchronize do
    store_column_attribute_tracker.has_name?(name)
  end
end
set_store_column_attribute_values_on_init() click to toggle source
# File lib/associate_jsonb/with_store_attribute.rb, line 86
def set_store_column_attribute_values_on_init
  lambda do
    self.class.store_column_attribute_names.each do |attr, opts|
      _write_attribute(attr, _read_attribute(opts[:store])[opts[:key]])
      clear_attribute_change(attr) if persisted?
    end
  rescue
    nil
  end
end
store_column_attribute(store, attr, cast_type = ActiveRecord::Type::Value.new, sql_type: nil, key: nil, **attribute_opts) click to toggle source
# File lib/associate_jsonb/with_store_attribute.rb, line 101
      def store_column_attribute(store, attr, cast_type = ActiveRecord::Type::Value.new, sql_type: nil, key: nil, **attribute_opts)
        store = store.to_sym
        attr = attr.to_sym
        key ||= attr
        key = key.to_s
        array = attribute_opts[:array]
        attribute attr, cast_type, **attribute_opts

        instance_eval <<~CODE, __FILE__, __LINE__ + 1
          add_store_column_attribute_name("#{attr}", :#{store}, "#{key}", { sql_type: sql_type, type: cast_type, opts: attribute_opts })
        CODE

        include WithStoreAttribute::InstanceMethodsOnActivation.new(self, store, attr, key, array)
      end
store_column_attribute_names() click to toggle source
Calls superclass method
# File lib/associate_jsonb/with_store_attribute.rb, line 66
def store_column_attribute_names
  store_column_attribute_tracker.synchronize do
    current_store_col_names = {}
    current_store_col_names.merge!(super) if defined? super
    current_store_col_names.merge!(store_column_attribute_tracker.names_list)
  end
end
store_column_attribute_tracker() click to toggle source
# File lib/associate_jsonb/with_store_attribute.rb, line 62
def store_column_attribute_tracker
  @store_column_attribute_tracker ||= initialize_store_column_attribute_tracker
end