Sha256: 023ccb9f4f35c399790d1c6481bbac829670913e9b9c0e1e399ba0e8dd0ae34a

Contents?: true

Size: 758 Bytes

Versions: 15

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true

module Ridgepole
  class DefaultsLimit
    DEFAULTS_LIMITS = {
      mysql2: {
        boolean: 1,
        integer: 4,
        bigint: 8,
        float: 24,
        string: 255,
        text: 65_535,
        binary: 65_535,
      },
    }.freeze

    class << self
      def default_limit(column_type, options)
        defaults = DEFAULTS_LIMITS[adapter] || {}
        option_key = :"default_#{column_type}_limit"
        default_limit = options[option_key] || defaults[column_type] || 0
        default_limit.zero? ? nil : default_limit
      end

      def adapter
        ActiveRecord::Base.connection_config.fetch(:adapter).to_sym
      rescue ActiveRecord::ConnectionNotEstablished
        nil
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ridgepole-0.8.12 lib/ridgepole/default_limit.rb
ridgepole-0.8.11 lib/ridgepole/default_limit.rb
ridgepole-0.8.10 lib/ridgepole/default_limit.rb
ridgepole-0.8.9 lib/ridgepole/default_limit.rb
ridgepole-0.8.8 lib/ridgepole/default_limit.rb
ridgepole-0.8.7 lib/ridgepole/default_limit.rb
ridgepole-0.8.6 lib/ridgepole/default_limit.rb
ridgepole-0.8.5 lib/ridgepole/default_limit.rb
ridgepole-0.8.4 lib/ridgepole/default_limit.rb
ridgepole-0.8.3 lib/ridgepole/default_limit.rb
ridgepole-0.8.2 lib/ridgepole/default_limit.rb
ridgepole-0.8.1 lib/ridgepole/default_limit.rb
ridgepole-0.8.0 lib/ridgepole/default_limit.rb
ridgepole-0.8.0.rc2 lib/ridgepole/default_limit.rb
ridgepole-0.7.8 lib/ridgepole/default_limit.rb