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
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 55
def handle_chart(chart)
fields = %w[units name description]
lines = chart.each_with_object([]) do |(k, v), a|
next unless fields.include?(k)
a << format('%<key>s = %<value>s', key: k, value: quote_value(v))
end
lines << "source = #{handle_sources(chart[:sources])}"
lines.to_hcl_obj(10)
end
|
#handle_charts(charts) ⇒ Object
51
52
53
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 51
def handle_charts(charts)
listmaker(charts, :handle_chart)
end
|
#handle_rows(rows) ⇒ Object
45
46
47
48
49
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 45
def handle_rows(rows)
rows.each_with_object([]) do |row, a|
a << "chart = #{handle_charts(row[:charts])}".braced(8)
end.to_hcl_list
end
|
#handle_source(source) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 72
def handle_source(source)
source.each_with_object([]) do |(k, v), a|
next unless source_fields.include?(k)
k = 'queryBuilderEnabled' if k == 'querybuilderEnabled'
a << format('%<key>s = %<value>s',
key: k.to_snake,
value: quote_value(v))
end.to_hcl_obj(14)
end
|
#handle_sources(sources) ⇒ Object
68
69
70
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 68
def handle_sources(sources)
listmaker(sources, :handle_source)
end
|
#hcl_fields ⇒ Object
21
22
23
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 21
def hcl_fields
%w[name description url sections parameter_details tags]
end
|
#khandle_sections ⇒ Object
25
26
27
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 25
def khandle_sections
'section'
end
|
#listmaker(vals, method) ⇒ String
Returns HCL list of vals.
34
35
36
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 34
def listmaker(vals, method)
vals.each_with_object([]) { |v, a| a << send(method, v) }.to_hcl_list
end
|
#qhandle_sections(val) ⇒ Object
89
90
91
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 89
def qhandle_sections(val)
val
end
|
#quote_value(val) ⇒ Object
93
94
95
96
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 93
def quote_value(val)
val.gsub!('$', '$$') if val.is_a?(String)
super
end
|
#source_fields ⇒ Object
84
85
86
87
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 84
def source_fields
%w[name query disabled scatterPlotSource querybuilderEnabled
sourceDescription]
end
|
#vhandle_sections(vals) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/wavefront-cli/output/hcl/dashboard.rb', line 38
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
|