Class: Integrity::Project

Inherits:
Object show all
Includes:
DataMapper::Resource
Defined in:
lib/integrity/project.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.only_public_unless(condition) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/integrity/project.rb', line 24

def self.only_public_unless(condition)
  if condition
    all
  else
    all(:public => true)
  end
end

Instance Method Details

#build(commit_identifier = "HEAD") ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/integrity/project.rb', line 32

def build(commit_identifier="HEAD")
  return if building?
  update_attributes(:building => true)
  ProjectBuilder.new(self).build(commit_identifier)
ensure
  update_attributes(:building => false)
  send_notifications
end

#config_for(notifier) ⇒ Object



72
73
74
75
# File 'lib/integrity/project.rb', line 72

def config_for(notifier)
  notifier = notifiers.first(:name => notifier.to_s.split(/::/).last)
  notifier.blank? ? {} : notifier.config
end

#enable_notifiers(*args) ⇒ Object



81
82
83
# File 'lib/integrity/project.rb', line 81

def enable_notifiers(*args)
  Notifier.enable_notifiers(id, *args)
end

#last_buildObject



53
54
55
# File 'lib/integrity/project.rb', line 53

def last_build
  all_builds.first
end

#notifies?(notifier) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/integrity/project.rb', line 77

def notifies?(notifier)
  !notifiers.first(:name => notifier.to_s.split(/::/).last).blank?
end

#previous_buildsObject



57
58
59
# File 'lib/integrity/project.rb', line 57

def previous_builds
  all_builds.tap {|builds| builds.shift }
end

#public=(flag) ⇒ Object



65
66
67
68
69
70
# File 'lib/integrity/project.rb', line 65

def public=(flag)
  attribute_set(:public, case flag
    when "1", "0" then flag == "1"
    else !!flag
  end)
end

#push(payload) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/integrity/project.rb', line 41

def push(payload)
  payload = JSON.parse(payload || "")

  if Integrity.config[:build_all_commits]
    payload["commits"].sort_by { |commit| Time.parse(commit["timestamp"]) }.each do |commit|
      build(commit["id"]) if payload["ref"] =~ /#{branch}/
    end
  else
    build(payload["after"]) if payload["ref"] =~ /#{branch}/
  end
end

#statusObject



61
62
63
# File 'lib/integrity/project.rb', line 61

def status
  last_build && last_build.status
end