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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62878c327e1da216456749f0d3d3b154a4d8d11528226f90cc7dadf855d2e6f2
4
- data.tar.gz: 7a27d00aca80c0a3837d1bfc7778ee1d507c2deb7719127a53745a86f25aa439
3
+ metadata.gz: 3a60d7dd7673c1ef147e8bc39818dab52fb12c8a55b30b5cb914f12d929b7cf5
4
+ data.tar.gz: 621d83b711bfa0856fe18787999839787b76cc75bfb1be6b84658b6a0e50ee2c
5
5
  SHA512:
6
- metadata.gz: 86f14f92c0a6b4953307c6a733daf0c378726f0e3d9f97703c29ff3e34ead58568b4b3d0d62ddd2cd34da40b6d1056cc6a6e1b096030276d6313745844a25998
7
- data.tar.gz: 51cb295e2097b87d2ba21faf62495087a5cae5a7db695e7703e219cbde57f883b4f776d39ca68258299ba6f33347c1bca3ce1608580b27f5a2e251f978c3c86f
6
+ metadata.gz: 181c52cfa7084f5513de2a1313f031035f817d347e8b389577c327942e41368d0fd67252dd15dec5dbd51cd595fccb87f897d032d4023c5c3186e98a75ffa024
7
+ data.tar.gz: 66cb585fbd41230d352d1c9f4e8a17bf44e5b96564e0c9eb868adcd1bb243795ba7edcf033b450acdb79a637a02b291a80b7887ec8b2aacb00d95efdcea4138b
data/README.md CHANGED
@@ -6,7 +6,7 @@ Logging mechanism using database triggers to store the old and new row states in
6
6
  ## Install
7
7
 
8
8
  ```
9
- gem install 'breathing'
9
+ gem install breathing
10
10
  ```
11
11
 
12
12
  ## Usage
@@ -2,7 +2,7 @@ $:.push File.expand_path('lib', __dir__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'breathing'
5
- s.version = '0.0.4'
5
+ s.version = '0.0.5'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Akira Kusumoto']
8
8
  s.email = ['akirakusumo10@gmail.com']
@@ -18,12 +18,17 @@ module Breathing
18
18
  sheet = @workbook.add_worksheet(table_name)
19
19
  end
20
20
 
21
- rows = Breathing::ChangeLog.where(table_name: table_name).where('id >= ?', id).order(:id)
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').change_font_bold(true)
37
- sheet.add_cell(0, 1, 'action').change_font_bold(true)
38
- sheet.add_cell(0, 2, 'id').change_font_bold(true)
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).change_font_bold(true)
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.action)
48
- sheet.add_cell(i, 2, row.transaction_id)
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
- data = row.action == 'DELETE' ? row.before_data : row.after_data
51
- cell_object = sheet.add_cell(i, j, data[column_name])
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, 'medium') if i.zero?
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
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-14 00:00:00.000000000 Z
11
+ date: 2020-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor