Sha256: 53be821c83a20e7b09e31d045fe0d89f6731f2425ca296c27229a5924ce0d6bf

Contents?: true

Size: 891 Bytes

Versions: 1

Compression:

Stored size: 891 Bytes

Contents

module Traits
  class Attribute
    module Type
      def type
        column_definition.type.to_sym
      end

      def string?
        type == :string
      end

      def text?
        type == :text
      end

      def binary?
        type == :binary
      end

      def big?
        text? || binary?
      end

      def integer?
        type == :integer
      end

      def float?
        type == :float
      end

      def decimal?
        type == :decimal
      end

      def real?
        float? || decimal?
      end

      def number?
        integer? || float? || decimal?
      end

      def datetime?
        type == :datetime
      end

      def active_record_timestamp?
        datetime? && (name == :created_at || name == :updated_at || name == :deleted_at)
      end

      def to_hash
        super.merge!(
          type: type
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-traits-1.0.0 lib/traits/concerns/attribute/type.rb