Sha256: 97a176f001d3ffdfeb7ac51dd0688bc15371e5aac00f0e5e802cfef2de0058a4

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

module ActiveRecord
  module ConnectionAdapters # :nodoc:
    module SchemaStatements
      alias __type_to_sql_enum type_to_sql

      # Add enumeration support for schema statement creation. This
      # will have to be adapted for every adapter if the type requires
      # anything by a list of allowed values. The overrides the standard
      # type_to_sql method and chains back to the default. This could 
      # be done on a per adapter basis, but is generalized here.
      #
      # will generate enum('a', 'b', 'c') for :limit => [:a, :b, :c]
      def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
        if type == :enum
          native = native_database_types[type]
          column_type_sql = native[:name] || 'enum'
          
          column_type_sql << "(#{limit.map { |v| quote(v) }.join(',')})"
          column_type_sql          
        else
          # Edge rails fallback for Rails 1.1.6. We can remove the
          # rescue once everyone has upgraded to 1.2.
          begin
            __type_to_sql_enum(type, limit, precision, scale)
          rescue ArgumentError
            __type_to_sql_enum(type, limit)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
smukherjee-openbill-0.1.5 vendor/plugins/enum-column/lib/enum/schema_statements.rb
smukherjee-openbill-0.1.6 vendor/plugins/enum-column/lib/enum/schema_statements.rb
smukherjee-openbill-0.1.7 vendor/plugins/enum-column/lib/enum/schema_statements.rb
enum_column-0.1.0 lib/enum/schema_statements.rb
openbill-0.1.5 vendor/plugins/enum-column/lib/enum/schema_statements.rb
openbill-0.1.6 vendor/plugins/enum-column/lib/enum/schema_statements.rb