Class: Lighthouse::Project

Inherits:
Object
  • Object
show all
Includes:
Buildmeister::JSONUtils, Buildmeister::StringUtils
Defined in:
lib/lighthouse/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Buildmeister::JSONUtils

#with_json_response

Methods included from Buildmeister::StringUtils

#divider

Constructor Details

#initialize(resource, attributes) ⇒ Project

Returns a new instance of Project.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lighthouse/project.rb', line 8

def initialize(resource, attributes)
  @id   = attributes['id']
  @name = attributes['name']

  @resource = resource

  # self.bins = []
  
  # bins.extend Finder
  
  # project_bins = bins

  # config['bins'].each do |bin_name|
    # bin = project_bins.find { |b| b.name == bin_name }
    # raise "No bin named #{bin_name}" unless bin 
    
    # bins << Buildmeister::Bin.new(bin, options[:mode], :annotations => config['annotations'])
  # end
  
  # config['personal_bins'].each do |bin_name|
    # bin = project_bins.find { |b| !b.shared && (b.name == bin_name) }
    # raise "No bin named #{bin_name}" unless bin 
    
    # bins << Buildmeister::Bin.new(bin, options[:mode], :annotations => config['annotations'])
  # end if config['personal_bins']
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/lighthouse/project.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/lighthouse/project.rb', line 6

def name
  @name
end

#resourceObject

Returns the value of attribute resource.



6
7
8
# File 'lib/lighthouse/project.rb', line 6

def resource
  @resource
end

Instance Method Details

#binsObject



35
36
37
38
39
40
41
42
43
# File 'lib/lighthouse/project.rb', line 35

def bins
  with_json_response( bins_resource.get(accept: 'json') ) do |r|
    r['ticket_bins'].map do |b|
      attrs = b['ticket_bin']

      Lighthouse::Bin.new(self, attrs)
    end
  end.tap { |a| a.extend(Buildmeister::Finder) }
end

#changed?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/lighthouse/project.rb', line 80

def changed?
  bins.any?(&:changed?)
end

#displayObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/lighthouse/project.rb', line 64

def display
  out = ''
  out << name + "\n"
  out << "#{divider}\n"
  
  bins.each do |bin|
    out << bin.display + "\n"
  end
  
  out
end

#find_tickets(*ids) ⇒ Object

There’s no good way to do this in the Lighthouse API. This is slow, but at least it’s easy to write.



58
59
60
61
62
# File 'lib/lighthouse/project.rb', line 58

def find_tickets(*ids)
  ids.map do |id|
    tickets(id).first
  end.compact
end

#refresh!Object



76
77
78
# File 'lib/lighthouse/project.rb', line 76

def refresh!
  bins.each(&:refresh!)
end

#tickets(query = "") ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/lighthouse/project.rb', line 45

def tickets(query = "")
  with_json_response( tickets_resource.get(params: {q: query}, accept: 'json') ) do |r|
    (r['tickets'] || []).map do |t|
      attrs = t['ticket']  
      id = attrs['number']
      
      Lighthouse::Ticket.new(tickets_resource[id], attrs)
    end
  end
end