Class: Build

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Matrix, Messages, States
Defined in:
lib/travis/model/build.rb,
lib/travis/model/build/matrix.rb,
lib/travis/model/build/states.rb,
lib/travis/model/build/messages.rb,
lib/travis/model/build/denormalize.rb,
lib/travis/model/build/notifications.rb

Defined Under Namespace

Modules: Denormalize, Matrix, Messages, Notifications, States

Constant Summary collapse

PER_PAGE =
10

Constants included from Matrix

Matrix::ENV_KEYS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Matrix

#matrix_finished?, #matrix_for, #matrix_status

Methods included from States

#color, #failed?, #finish, #passed?, #pending?, #start

Methods included from Messages

#human_status_message, #status_message

Class Method Details

.descendingObject



51
52
53
# File 'lib/travis/model/build.rb', line 51

def descending
  order(arel_table[:id].desc)
end

.finishedObject



34
35
36
# File 'lib/travis/model/build.rb', line 34

def finished
  where(:state => 'finished')
end

.last_finished_on_branch(branches) ⇒ Object



47
48
49
# File 'lib/travis/model/build.rb', line 47

def last_finished_on_branch(branches)
  finished.on_branch(branches).descending.first
end

.next_numberObject



61
62
63
# File 'lib/travis/model/build.rb', line 61

def next_number
  maximum(floor('number')).to_i + 1
end

.on_branch(branches) ⇒ Object



38
39
40
41
# File 'lib/travis/model/build.rb', line 38

def on_branch(branches)
  branches = normalize_to_array(branches)
  joins(:commit).where(branches.present? ? ["commits.branch IN (?)", branches] : [])
end

.paged(options) ⇒ Object



55
56
57
58
59
# File 'lib/travis/model/build.rb', line 55

def paged(options)
  # TODO should use an offset when we use limit!
  # offset(PER_PAGE * options[:offset]).limit(options[:page])
  limit(PER_PAGE * (options[:page] || 1).to_i)
end

.previous(build) ⇒ Object



43
44
45
# File 'lib/travis/model/build.rb', line 43

def previous(build)
  where("builds.repository_id = ? AND builds.id < ?", build.repository_id, build.id).finished.descending.limit(1).first
end

.recent(options = {}) ⇒ Object



26
27
28
# File 'lib/travis/model/build.rb', line 26

def recent(options = {})
  was_started.descending.paged(options).includes([:commit, { :matrix => :commit }])
end

.was_startedObject



30
31
32
# File 'lib/travis/model/build.rb', line 30

def was_started
  where(:state => ['started', 'finished'])
end

Instance Method Details

#config=(config) ⇒ Object



85
86
87
# File 'lib/travis/model/build.rb', line 85

def config=(config)
  super(config.deep_symbolize_keys)
end

#previous_on_branchObject



81
82
83
# File 'lib/travis/model/build.rb', line 81

def previous_on_branch
  Build.on_branch(commit.branch).previous(self)
end