Sha256: 4d9bdbe706f5e75833520aa0a6f7060cb1c4afcd8b18731de59ae932ba26d668

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module Valle
  module AbstractAdapter
    class ColumnWrapper

      class << self

        ##
        # Wraps original column
        #
        # @param [ActiveRecord::ConnectionAdapters::Column] original_column the original column
        #
        def wrap(original_column)
          case
          when limit_in_bytes?(original_column)
            ByteLimitedColumn.new(original_column)
          when limit_in_characters?(original_column)
            CharacterLimitedColumn.new(original_column)
          else
            UnlimitedColumn.new(original_column)
          end
        end

        private

        ##
        # Determines whether the limit's method returned value is count of bytes
        #
        # Limit is number of bytes for :binary and :integer columns.
        # @see http://apidock.com/rails/ActiveRecord/ConnectionAdapters/TableDefinition/column
        #
        def limit_in_bytes?(column)
          case column.type
          # when :binary; true
          when :integer; true
          else false
          end
        end

        ##
        # Determines whether the limit's method returned value is count of characters
        #
        # Limit is number of characters for :string and :text columns
        # @see http://apidock.com/rails/ActiveRecord/ConnectionAdapters/TableDefinition/column
        #
        def limit_in_characters?(column)
          case column.type
          when :string; true
          when :text; true
          else false
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
valle-0.0.2 lib/valle/abstract_adapter/column_wrapper.rb