Class: Multisync::Summary
- Inherits:
-
Object
- Object
- Multisync::Summary
show all
- Includes:
- Colors
- Defined in:
- lib/multisync/summary.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Colors
#as_fail, #as_main, #as_note, #as_skipped, #as_success
Constructor Details
#initialize(tasks) ⇒ Summary
Returns a new instance of Summary.
7
8
9
|
# File 'lib/multisync/summary.rb', line 7
def initialize tasks
@tasks = tasks
end
|
Instance Attribute Details
#tasks ⇒ Object
All tasks to include in the summary
5
6
7
|
# File 'lib/multisync/summary.rb', line 5
def tasks
@tasks
end
|
Instance Method Details
#as_message(message) ⇒ Object
79
80
81
|
# File 'lib/multisync/summary.rb', line 79
def as_message message
{value: message, colspan: 6}
end
|
#data ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/multisync/summary.rb', line 26
def data
tasks.map do |task|
result = task.result
desc = [task.source_description, task.destination_description]
case result[:action]
when :run
if result[:status]&.success?
stats = Multisync::RsyncStat.new(result[:stdout])
[*desc, *stats.formatted_values.map { {value: as_success(_1), alignment: :right} }]
else
[*desc, as_message(as_fail("Failed, for more information see details below"))]
end
when :skip
[*desc, as_message(as_skipped(result[:skip_message]))]
else
[*desc, as_message(as_note("not executed"))]
end
end.push(
[
as_note("Total"),
"",
*Multisync::RsyncStat
.formatted_totals
.map { {value: as_note(_1), alignment: :right} }
]
)
end
|
#failures ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/multisync/summary.rb', line 62
def failures
tasks
.select { _1.result[:action] == :run && !_1.result[:status]&.success? }
.flat_map do |task|
[
as_fail([task.source_description, task.destination_description].join(" --> ")),
message_or_nil(task.result[:stdout]),
message_or_nil(task.result[:stderr]),
""
].compact
end
.tap { _1.unshift "\n#{as_main("Failures")}" if _1.any? }
.then { _1.any? ? _1.join("\n") : nil }
end
|
#headings ⇒ Object
19
20
21
22
23
24
|
# File 'lib/multisync/summary.rb', line 19
def headings
%w[SOURCE DESTINATION FILES + - → ∑ ↑]
.map(&method(:as_note))
.zip(%i[left left right right right right right right])
.map { |v, a| {value: v, alignment: a} }
end
|
#message_or_nil(message) ⇒ Object
83
84
85
|
# File 'lib/multisync/summary.rb', line 83
def message_or_nil message
(message.nil? || message.empty?) ? nil : message
end
|
#table ⇒ Object
15
16
17
|
# File 'lib/multisync/summary.rb', line 15
def table
Terminal::Table.new(headings: headings, rows: data, style: table_style)
end
|
#table_style ⇒ Object
87
88
89
|
# File 'lib/multisync/summary.rb', line 87
def table_style
{border_x: as_note("─"), border_y: "", border_i: "", border_top: false, border_bottom: false, padding_left: 0, padding_right: 3}
end
|
#to_s ⇒ Object
11
12
13
|
# File 'lib/multisync/summary.rb', line 11
def to_s
["", as_main("Summary"), table.to_s, failures].compact.join("\n")
end
|