Class: Debci::HTML::JSON

Inherits:
Rooted
  • Object
show all
Defined in:
lib/debci/html.rb

Instance Attribute Summary collapse

Attributes inherited from Rooted

#root

Instance Method Summary collapse

Constructor Details

#initialize(suite, arch) ⇒ JSON

Returns a new instance of JSON.



88
89
90
91
92
# File 'lib/debci/html.rb', line 88

def initialize(suite, arch)
  super()
  self.suite = suite
  self.arch = arch
end

Instance Attribute Details

#archObject

Returns the value of attribute arch.



82
83
84
# File 'lib/debci/html.rb', line 82

def arch
  @arch
end

#suiteObject

Returns the value of attribute suite.



81
82
83
# File 'lib/debci/html.rb', line 81

def suite
  @suite
end

Instance Method Details

#datadirObject



84
85
86
# File 'lib/debci/html.rb', line 84

def datadir
  'status'
end

#historyObject



122
123
124
125
126
127
128
# File 'lib/debci/html.rb', line 122

def history
  status_history = (root / suite / arch).glob('[0-9]*/[0-9]*/[0-9]*.json')
  status_history_data = status_history.sort.map { |f| ::JSON.parse(f.read) }

  h = root / suite / arch / 'history.json'
  h.write(::JSON.pretty_generate(status_history_data))
end

#packagesObject



130
131
132
133
# File 'lib/debci/html.rb', line 130

def packages
  p = root / suite / arch / 'packages.json'
  p.write(::JSON.pretty_generate(status_packages_data.as_json))
end

#statusObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/debci/html.rb', line 98

def status
  data = {
    pass: 0,
    fail: 0,
    neutral: 0,
    tmpfail: 0,
    total: 0,
  }
  status_packages_data.each do |pkg|
    data[pkg["status"].to_sym] += 1
    data[:total] += 1
  end
  data[:date] = Time.now.strftime('%Y-%m-%dT%H:%M:%S')

  output = ::JSON.pretty_generate(data)

  today = root / suite / arch / Time.now.strftime('%Y/%m/%d.json')
  today.parent.mkpath
  today.write(output)

  current = root / suite / arch / 'status.json'
  current.write(output)
end

#status_packages_dataObject



94
95
96
# File 'lib/debci/html.rb', line 94

def status_packages_data
  @status_packages_data ||= Debci::Job.status_on(suite, arch)
end