Class: Travis::Surveillance::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/travis/surveillance/project.rb

Constant Summary collapse

ATTRIBUTES =
[:description, :id, :slug]

Instance Method Summary collapse

Constructor Details

#initialize(slug) ⇒ Project

Returns a new instance of Project.



17
18
19
20
# File 'lib/travis/surveillance/project.rb', line 17

def initialize(slug)
  self.attributes = { 'slug' => slug }
  populate
end

Instance Method Details

#add_build(json) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/travis/surveillance/project.rb', line 28

def add_build(json)
  if build = build_for(json['id'])
    return build
  end

  build = Build.new(json.merge({'project' => self}))
  builds << build
  build
end

#api_urlObject



70
71
72
# File 'lib/travis/surveillance/project.rb', line 70

def api_url
  @api_url ||= "https://api.travis-ci.org/repos/#{@slug}"
end

#attributes=(attrs = {}) ⇒ Object



22
23
24
25
26
# File 'lib/travis/surveillance/project.rb', line 22

def attributes=(attrs = {})
  attrs.each do |key, value|
    send("#{key}=", value) if ATTRIBUTES.include?(key.to_sym)
  end
end

#build_for(id) ⇒ Object



38
39
40
# File 'lib/travis/surveillance/project.rb', line 38

def build_for(id)
  builds.find { |b| b.id == id }
end

#building?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/travis/surveillance/project.rb', line 42

def building?
  status.nil?
end

#buildsObject



46
47
48
# File 'lib/travis/surveillance/project.rb', line 46

def builds
  @builds ||= Builds.new
end

#failed?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/travis/surveillance/project.rb', line 50

def failed?
  !status.nil? && !passed?
end

#nameObject



58
59
60
# File 'lib/travis/surveillance/project.rb', line 58

def name
  @name ||= @slug.split('/')[1]
end

#ownerObject



62
63
64
# File 'lib/travis/surveillance/project.rb', line 62

def owner
  @owner ||= @slug.split('/')[0]
end

#passed?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/travis/surveillance/project.rb', line 54

def passed?
  !status.nil? && status.zero?
end

#statusObject



66
67
68
# File 'lib/travis/surveillance/project.rb', line 66

def status
  builds.last.result if builds.any?
end

#urlObject



74
75
76
# File 'lib/travis/surveillance/project.rb', line 74

def url
  @url ||= "https://travis-ci.org/#{@slug}"
end