Sha256: 106d75c090c84136afcb92caf0b67f7245fe0530d14bd66b77ecee96067025a6

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module RailsAdmin
  module Adapters
    module ActiveRecord
      class Property
        attr_reader :property, :model

        def initialize(property, model)
          @property = property
          @model = model
        end

        def name
          property.name.to_sym
        end

        def pretty_name
          property.name.to_s.tr('_', ' ').capitalize
        end

        def type
          if serialized?
            :serialized
          else
            property.type
          end
        end

        def length
          property.limit
        end

        def nullable?
          property.null
        end

        def serial?
          model.primary_key == property.name
        end

        def association?
          false
        end

        def read_only?
          model.readonly_attributes.include? property.name.to_s
        end

      private

        def serialized?
          model.type_for_attribute(property.name).instance_of?(::ActiveRecord::Type::Serialized)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rails_admin-3.3.0 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.2.1 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.2.0 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.2.0.rc lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.2.0.beta lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.4 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.3 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.2 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.1 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.0 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.0.rc2 lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.0.rc lib/rails_admin/adapters/active_record/property.rb
rails_admin-3.1.0.beta lib/rails_admin/adapters/active_record/property.rb