breathing 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/breathing.gemspec +1 -1
- data/lib/breathing/excel.rb +48 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a60d7dd7673c1ef147e8bc39818dab52fb12c8a55b30b5cb914f12d929b7cf5
|
4
|
+
data.tar.gz: 621d83b711bfa0856fe18787999839787b76cc75bfb1be6b84658b6a0e50ee2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 181c52cfa7084f5513de2a1313f031035f817d347e8b389577c327942e41368d0fd67252dd15dec5dbd51cd595fccb87f897d032d4023c5c3186e98a75ffa024
|
7
|
+
data.tar.gz: 66cb585fbd41230d352d1c9f4e8a17bf44e5b96564e0c9eb868adcd1bb243795ba7edcf033b450acdb79a637a02b291a80b7887ec8b2aacb00d95efdcea4138b
|
data/README.md
CHANGED
data/breathing.gemspec
CHANGED
data/lib/breathing/excel.rb
CHANGED
@@ -18,12 +18,17 @@ module Breathing
|
|
18
18
|
sheet = @workbook.add_worksheet(table_name)
|
19
19
|
end
|
20
20
|
|
21
|
-
rows
|
21
|
+
rows = Breathing::ChangeLog.where(table_name: table_name).where('id >= ?', id).order(:id)
|
22
|
+
column_widths = []
|
22
23
|
|
23
24
|
if first_row = rows.first
|
24
|
-
add_header_row(sheet, first_row)
|
25
|
+
add_header_row(sheet, first_row, column_widths)
|
26
|
+
end
|
27
|
+
add_body_rows(sheet, rows, column_widths)
|
28
|
+
|
29
|
+
column_widths.each.with_index(0) do |size, i|
|
30
|
+
sheet.change_column_width(i, size + 2)
|
25
31
|
end
|
26
|
-
add_body_rows(sheet, rows)
|
27
32
|
add_style(sheet)
|
28
33
|
end
|
29
34
|
|
@@ -32,23 +37,52 @@ module Breathing
|
|
32
37
|
|
33
38
|
private
|
34
39
|
|
35
|
-
def add_header_row(sheet, row)
|
36
|
-
sheet.add_cell(0, 0, 'change_logs.id').
|
37
|
-
|
38
|
-
|
40
|
+
def add_header_row(sheet, row, column_widths)
|
41
|
+
sheet.add_cell(0, 0, 'change_logs.id').tap do |cell|
|
42
|
+
cell.change_font_bold(true)
|
43
|
+
cell.change_fill('ddedf3') # color: blue
|
44
|
+
end
|
45
|
+
sheet.add_cell(0, 1, 'change_logs.created_at').tap do |cell|
|
46
|
+
cell.change_font_bold(true)
|
47
|
+
cell.change_fill('ddedf3') # color: blue
|
48
|
+
end
|
49
|
+
sheet.add_cell(0, 2, 'action').tap do |cell|
|
50
|
+
cell.change_font_bold(true)
|
51
|
+
cell.change_fill('ddedf3') # color: blue
|
52
|
+
end
|
53
|
+
sheet.add_cell(0, 3, 'id').tap do |cell|
|
54
|
+
cell.change_font_bold(true)
|
55
|
+
cell.change_fill('ddedf3') # color: blue
|
56
|
+
end
|
57
|
+
|
58
|
+
column_widths << 'change_logs.id'.size
|
59
|
+
column_widths << 'change_logs.created_at'.size
|
60
|
+
column_widths << 'action'.size
|
61
|
+
column_widths << 'id'.size
|
62
|
+
|
39
63
|
row.data_column_names.each.with_index(3) do |column_name, i|
|
40
|
-
sheet.add_cell(0, i, column_name)
|
64
|
+
cell = sheet.add_cell(0, i, column_name)
|
65
|
+
cell.change_font_bold(true)
|
66
|
+
cell.change_fill('ddedf3') # color: blue
|
67
|
+
column_widths << column_name.size
|
41
68
|
end
|
42
69
|
end
|
43
70
|
|
44
|
-
def add_body_rows(sheet, rows)
|
71
|
+
def add_body_rows(sheet, rows, column_widths)
|
45
72
|
rows.each.with_index(1) do |row, i|
|
73
|
+
column_widths[0] = row.id.to_s.size if column_widths[0] < row.id.to_s.size
|
74
|
+
column_widths[2] = row.transaction_id.to_s.size if column_widths[2] < row.transaction_id.to_s.size
|
46
75
|
sheet.add_cell(i, 0, row.id)
|
47
|
-
sheet.add_cell(i, 1, row.
|
48
|
-
sheet.add_cell(i, 2, row.
|
76
|
+
sheet.add_cell(i, 1, row.created_at.to_s(:db))
|
77
|
+
sheet.add_cell(i, 2, row.action)
|
78
|
+
sheet.add_cell(i, 3, row.transaction_id)
|
79
|
+
|
80
|
+
data = row.action == 'DELETE' ? row.before_data : row.after_data
|
81
|
+
|
49
82
|
row.data_column_names.each.with_index(3) do |column_name, j|
|
50
|
-
|
51
|
-
|
83
|
+
value = data[column_name].to_s
|
84
|
+
column_widths[j] = value.size if column_widths[j] < value.size
|
85
|
+
cell_object = sheet.add_cell(i, j, value)
|
52
86
|
if row.action == 'UPDATE' && column_name != 'updated_at' && row.changed_attribute_columns.include?(column_name)
|
53
87
|
cell_object.change_fill('ffff00') # color: yellow
|
54
88
|
elsif row.action == 'DELETE'
|
@@ -65,7 +99,7 @@ module Breathing
|
|
65
99
|
cell.change_border(direction, 'thin')
|
66
100
|
end
|
67
101
|
|
68
|
-
cell.change_border(:bottom, '
|
102
|
+
cell.change_border(:bottom, 'double') if i.zero?
|
69
103
|
end
|
70
104
|
end
|
71
105
|
sheet.change_row_horizontal_alignment(0, 'center')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breathing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Kusumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|