Sha256: a2fd68896c9087b7eefa66396d04cc65b534c7519b16330210695bce5e364b4c

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 Bytes

Contents

module Superstore
  module ModelSchema
    extend ActiveSupport::Concern

    included do
      class_attribute :superstore_column, default: 'document'
    end

    module ClassMethods
      def attributes_builder # :nodoc:
        @attributes_builder ||= ActiveModel::AttributeSet::Builder.new(attribute_types, _default_attributes)
      end

      def load_schema! # :nodoc:
        @columns_hash = {}

        attributes_to_define_after_schema_loads.each do |name, (type, options)|
          if type.is_a?(Symbol)
            type = ActiveRecord::Type.lookup(type, **options.except(:default))
          end

          define_attribute(name, type, **options.slice(:default))
        end
      end

      def attribute_names
        attribute_types.keys
      end

      def column_names
        attribute_names
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
superstore-3.0.0 lib/superstore/model_schema.rb
superstore-2.5.0 lib/superstore/model_schema.rb