Sha256: 8e13629620b3cdaf4f19b3ed5c931cbebce0d34c0aa93eee5086722af4184eef

Contents?: true

Size: 584 Bytes

Versions: 1

Compression:

Stored size: 584 Bytes

Contents

require 'active_record'

class ActiveRecord::Base
  SQL = {
    :floor => {
      'postgresql' => 'floor(%s::float)',
      'mysql'      => 'floor(%s)',
      'sqlite3'    => 'round(%s - 0.5)'
    }
  }
  class << self
    def floor(field)
      SQL[:floor][adapter] % field
    end

    # TODO extract this to somewhere else and use Travis.config.env instead
    def adapter
      env = defined?(Rails) ? Rails.env : ENV['RAILS_ENV'] || ENV['ENV'] || 'test'
      adapter = configurations[env]['adapter']
      adapter == 'jdbcpostgresql' ? 'postgresql' : adapter
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-core-0.0.1 lib/core_ext/active_record/base.rb