Class: WavefrontHclOutput::Dashboard
- Inherits:
-
Base
- Object
- Base
- WavefrontHclOutput::Dashboard
show all
- Defined in:
- lib/wavefront-cli/output/hcl/dashboard.rb
Overview
Instance Attribute Summary
Attributes inherited from Base
#options, #resp
Instance Method Summary
collapse
Methods inherited from Base
#close_output, #handler, #initialize, #open_output, #required_fields, #resource_name, #run, #vhandle_tags
Instance Method Details
#handle_chart(chart) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 53
def handle_chart(chart)
fields = %w[units name description]
lines = chart.each_with_object([]) do |(k, v), a|
a.<< format('%s = %s', k, quote_value(v)) if fields.include?(k)
end
lines.<< "source = #{handle_sources(chart[:sources])}"
lines.to_hcl_obj(10)
end
|
#handle_charts(charts) ⇒ Object
49
50
51
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 49
def handle_charts(charts)
listmaker(charts, :handle_chart)
end
|
#handle_rows(rows) ⇒ Object
43
44
45
46
47
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 43
def handle_rows(rows)
rows.each_with_object([]) do |row, a|
a.<< ('chart = ' + handle_charts(row[:charts]).to_s).braced(8)
end.to_hcl_list
end
|
#handle_source(source) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 68
def handle_source(source)
fields = %w[name query disabled scatterPlotSource querybuilderEnabled
sourceDescription]
source.each_with_object([]) do |(k, v), a|
if fields.include?(k)
k = 'queryBuilderEnabled' if k == 'querybuilderEnabled'
a.<< format('%s = %s', k.to_snake, quote_value(v))
end
end.to_hcl_obj(14)
end
|
#handle_sources(sources) ⇒ Object
64
65
66
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 64
def handle_sources(sources)
listmaker(sources, :handle_source)
end
|
#hcl_fields ⇒ Object
19
20
21
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 19
def hcl_fields
%w[name description url sections parameter_details tags]
end
|
#khandle_sections ⇒ Object
23
24
25
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 23
def khandle_sections
'section'
end
|
#listmaker(vals, method) ⇒ String
Returns HCL list of vals.
32
33
34
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 32
def listmaker(vals, method)
vals.each_with_object([]) { |v, a| a.<< send(method, v) }.to_hcl_list
end
|
#qhandle_sections(val) ⇒ Object
80
81
82
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 80
def qhandle_sections(val)
val
end
|
#quote_value(val) ⇒ Object
84
85
86
87
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 84
def quote_value(val)
val.gsub!(/\$/, '$$') if v.is_a?(String)
super
end
|
#vhandle_sections(vals) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 36
def vhandle_sections(vals)
vals.each_with_object([]) do |section, a|
a.<< ("name = \"#{section[:name]}\"\n row = " +
handle_rows(section[:rows])).braced(4)
end.to_hcl_list
end
|