Sha256: 40aca57f260d3d6d27b60fad795681c6eaf43f6b2c1192b62827021a3cfa0229

Contents?: true

Size: 760 Bytes

Versions: 1

Compression:

Stored size: 760 Bytes

Contents

module PersistedAttributes
  class Attribute < ApplicationRecord
    DEFAULT_ATTRIBUTE_TYPE = :string

    AVAILABLE_ATTRIBUTE_TYPES = %i[
      string
      boolean
      integer
    ].freeze

    belongs_to :record, polymorphic: true

    validates :name, presence: true
    validates :name, uniqueness: { scope: [:record_type, :record_id] }

    class << self
      def attribute_class_for_attribute_type(attribute_type)
        case attribute_type
        when :string
          return "PersistedAttributes::Attribute::StringAttribute"
        when :integer
          return "PersistedAttributes::Attribute::IntegerAttribute"
        when :boolean
          return "PersistedAttributes::Attribute::BooleanAttribute"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
persisted_attributes-0.1.0 app/models/persisted_attributes/attribute.rb