Class: Travis::Surveillance::Project
- Inherits:
-
Object
- Object
- Travis::Surveillance::Project
- Defined in:
- lib/travis/surveillance/project.rb
Constant Summary collapse
- ATTRIBUTES =
[:description, :id, :slug]
Instance Method Summary collapse
- #add_build(json) ⇒ Object
- #api_url ⇒ Object
- #attributes=(attrs = {}) ⇒ Object
- #build_for(id) ⇒ Object
- #building? ⇒ Boolean
- #builds ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(slug) ⇒ Project
constructor
A new instance of Project.
- #name ⇒ Object
- #owner ⇒ Object
- #passed? ⇒ Boolean
- #status ⇒ Object
- #url ⇒ Object
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_url ⇒ Object
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
42 43 44 |
# File 'lib/travis/surveillance/project.rb', line 42 def building? status.nil? end |
#builds ⇒ Object
46 47 48 |
# File 'lib/travis/surveillance/project.rb', line 46 def builds @builds ||= Builds.new end |
#failed? ⇒ Boolean
50 51 52 |
# File 'lib/travis/surveillance/project.rb', line 50 def failed? !status.nil? && !passed? end |
#name ⇒ Object
58 59 60 |
# File 'lib/travis/surveillance/project.rb', line 58 def name @name ||= @slug.split('/')[1] end |
#owner ⇒ Object
62 63 64 |
# File 'lib/travis/surveillance/project.rb', line 62 def owner @owner ||= @slug.split('/')[0] end |
#passed? ⇒ Boolean
54 55 56 |
# File 'lib/travis/surveillance/project.rb', line 54 def passed? !status.nil? && status.zero? end |
#status ⇒ Object
66 67 68 |
# File 'lib/travis/surveillance/project.rb', line 66 def status builds.last.result if builds.any? end |
#url ⇒ Object
74 75 76 |
# File 'lib/travis/surveillance/project.rb', line 74 def url @url ||= "https://travis-ci.org/#{@slug}" end |