Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/active_record/base.rb

Direct Known Subclasses

Artifact, Build, Commit, Job, Repository, Request, Token, User, Worker

Constant Summary collapse

SQL =
{
  :floor => {
    'postgresql' => 'floor(%s::float)',
    'mysql'      => 'floor(%s)',
    'sqlite3'    => 'round(%s - 0.5)'
  }
}

Class Method Summary collapse

Class Method Details

.adapterObject

TODO extract this to somewhere else and use Travis.config.env instead



17
18
19
20
21
# File 'lib/core_ext/active_record/base.rb', line 17

def adapter
  env = defined?(Rails) ? Rails.env : ENV['RAILS_ENV'] || ENV['ENV'] || 'test'
  adapter = configurations[env]['adapter']
  adapter == 'jdbcpostgresql' ? 'postgresql' : adapter
end

.floor(field) ⇒ Object



12
13
14
# File 'lib/core_ext/active_record/base.rb', line 12

def floor(field)
  SQL[:floor][adapter] % field
end