Sha256: f5015da60de21bd239376b56f996c046ddfd142be6985e2537c373082be5368d

Contents?: true

Size: 843 Bytes

Versions: 8

Compression:

Stored size: 843 Bytes

Contents

# frozen_string_literal: true

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

    DEFAULTS_LIMITS = {
      mysql2: DEFAULT_LIMIT_FOR_MYSQL,
      trilogy: DEFAULT_LIMIT_FOR_MYSQL,
    }.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.adapter_name.downcase.to_sym
      rescue ActiveRecord::ConnectionNotEstablished
        nil
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ridgepole-3.0.0 lib/ridgepole/default_limit.rb
ridgepole-2.1.1 lib/ridgepole/default_limit.rb
ridgepole-2.1.0 lib/ridgepole/default_limit.rb
ridgepole-2.0.3 lib/ridgepole/default_limit.rb
ridgepole-2.0.2 lib/ridgepole/default_limit.rb
ridgepole-2.0.1 lib/ridgepole/default_limit.rb
ridgepole-2.0.0 lib/ridgepole/default_limit.rb
ridgepole-2.0.0.beta2 lib/ridgepole/default_limit.rb