Sha256: 293cd7384579951220262c53415f715a4ab08a67a81409fbdde2f7ae1cc0ffd8

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    class Column
      def initialize_with_enum name, default, sql_type=nil, *args
        initialize_without_enum name, default, sql_type, *args
        @type = simplified_type_with_enum sql_type
        @limit = extract_limit_with_enum sql_type
        @default = extract_default_with_enum default
      end
      alias_method :initialize_without_enum, :initialize
      alias_method :initialize, :initialize_with_enum

      def simplified_type_with_enum field_type
        if field_type =~ /enum|set/i
          $&.to_sym
        else
          simplified_type field_type
        end
      end

      def extract_limit_with_enum field_type
        if field_type =~ /(?:enum|set)\(([^)]+)\)/i
          $1.scan( /'([^']*)'/ ).flatten
        else
          extract_limit field_type
        end
      end

      def extract_default_with_enum default
        if type == :set
          default.split "," if default.present?
        else
          extract_default default
        end
      end

      def set?
        type == :set
      end

      def enum?
        type == :enum
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
native_enum-2.0.0 lib/native_enum/activerecord_enum_pre42.rb
activerecord_enum-0.4.1 lib/activerecord_enum/activerecord_enum_pre42.rb
native_enum-1.0.0 lib/native_enum/activerecord_enum_pre42.rb
native_enum-1.0.0pre1 lib/native_enum/activerecord_enum_pre42.rb
activerecord_enum-0.4.0 lib/activerecord_enum/activerecord_enum_pre42.rb