breathing 0.0.9 → 0.0.11

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: 78f7bd77e2aacd87fe91b8e42eeb8dd590fac1a067c90c092a8069fa9d2a391f
4
- data.tar.gz: cb6802aa877aa675fe62170d7d3fde082b1262439c33409a5a38169c90a05c8e
3
+ metadata.gz: 590240e0f1d36a691aa8d0bf85e96dad188fe49d69d40574165fc81795cda837
4
+ data.tar.gz: a7dbd3cdea44b2fda843e9376f0b25f9b9606d0cc381484beef9d9b34c3bdaf6
5
5
  SHA512:
6
- metadata.gz: 1610bf010d660a7f0c1f00ed61b3235e75497220ef2b21c0f9a5c200b2c670c8495cbf905b782c7202f0236549e086296141d6e3d1b5fd1c24684d3a3af69335
7
- data.tar.gz: 22d2262edfd99554875fbbaec0edac113c5e970a41f32126f7ebf18cc7b141987f9c58b1da1c02f4c1257e8f07a07e4a9a269c8876f6957bcc10cbac3767b161
6
+ metadata.gz: b457e63a0d0776df1b1278b7b0fb77e6b9c50d323b327d44aa258484ca3a6ca4673edea85b4dce8f0e7f81d09083c45408ff4f87199da0b668ef2983fafd3137
7
+ data.tar.gz: 81c4488c9e47f35bf8d3ffcdc6996909ef8c15f67383037c9a7e3b6104c28d77ba100b2a13c92c6d131a208745d830ce075081b77b94afef298fdf74069cbf3a
data/.circleci/config.yml CHANGED
@@ -4,13 +4,12 @@ executors:
4
4
  default:
5
5
  working_directory: ~/app
6
6
  docker:
7
- - image: circleci/ruby:2.6
7
+ - image: cimg/ruby:3.2.2
8
8
  environment:
9
9
  DB_USER: root
10
10
  DB_HOST: '127.0.0.1'
11
11
  - image: circleci/mysql:8-ram
12
12
  environment:
13
- MYSQL_USER: root
14
13
  MYSQL_ROOT_PASSWORD: root
15
14
  MYSQL_DATABASE: breathing_test
16
15
  command: [--default-authentication-plugin=mysql_native_password]
data/README.md CHANGED
@@ -75,7 +75,7 @@ Cleanup command.
75
75
 
76
76
  ## Compatibility
77
77
 
78
- - Ruby 2.3.0+
78
+ - Ruby 3.0.0+
79
79
  - MySQL 5.7.0+
80
80
  - PostgreSQL 8.0+
81
81
 
data/breathing.gemspec CHANGED
@@ -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.9'
5
+ s.version = '0.0.11'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Akira Kusumoto']
8
8
  s.email = ['akirakusumo10@gmail.com']
@@ -19,13 +19,15 @@ Gem::Specification.new do |s|
19
19
  s.bindir = 'exe'
20
20
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  s.add_runtime_dependency 'thor'
22
+ s.required_ruby_version = '>= 3.0'
22
23
 
23
- s.add_dependency 'activerecord', ['>= 6.0.0']
24
+ s.add_dependency 'activerecord', ['>= 7.0.0']
24
25
  s.add_dependency 'hairtrigger'
25
26
  s.add_dependency 'mysql2'
26
27
  s.add_dependency 'pg'
27
28
  s.add_dependency 'terminal-table'
28
29
  s.add_dependency 'rubyXL', ['>= 3.4.0']
30
+ s.add_development_dependency 'rake'
29
31
  s.add_development_dependency 'pry-byebug'
30
32
  s.add_development_dependency 'rspec', '~> 3.9'
31
33
  end
@@ -19,7 +19,7 @@ module Breathing
19
19
 
20
20
  def data_attributes
21
21
  data_column_names.each.with_object('change_logs.id' => id,
22
- 'change_logs.created_at' => created_at.to_s(:db),
22
+ 'change_logs.created_at' => created_at.to_fs(:db),
23
23
  'action' => action,
24
24
  'id' => transaction_id) do |name, hash|
25
25
  hash[name] = data[name]
@@ -29,21 +29,19 @@ module Breathing
29
29
  def diff
30
30
  return nil if action != 'UPDATE'
31
31
 
32
- changed_attribute_columns.each.with_object({}) do |column_name, diff_hash|
33
- diff_hash[column_name] = {before_data[column_name] => after_data[column_name]}
34
- end
32
+ changed_attribute_columns.map do |column_name|
33
+ "#{column_name}: #{before_data[column_name]} -> #{after_data[column_name]}"
34
+ end.join(" \n")
35
35
  end
36
36
 
37
37
  def attributes_for_excel
38
38
  {
39
39
  'change_logs.id' => id,
40
- 'created_at' => created_at.to_s(:db),
40
+ 'created_at' => created_at.to_fs(:db),
41
41
  'table_name' => table_name,
42
42
  'action' => action,
43
43
  'id' => transaction_id,
44
- 'diff' => diff.to_s,
45
- 'before_data' => before_data.to_s,
46
- 'after_data' => after_data.to_s,
44
+ 'diff' => diff
47
45
  }
48
46
  end
49
47
  end
@@ -27,8 +27,10 @@ module Breathing
27
27
  add_style(sheet)
28
28
  end
29
29
 
30
- add_change_logs_sheet(id) if table_names.size.positive?
31
-
30
+ if table_names.size.positive?
31
+ add_change_logs_sheet(id)
32
+ @workbook.worksheets.rotate!(-1)
33
+ end
32
34
  @workbook.write(file_name)
33
35
  end
34
36
 
@@ -36,9 +38,17 @@ module Breathing
36
38
 
37
39
  def add_header_row(sheet, row)
38
40
  header_color = 'ddedf3' # blue
41
+ foreign_keys = ActiveRecord::Base.connection.foreign_keys(sheet.sheet_name)
39
42
  row.data_attributes.keys.each.with_index do |header_column, column_index|
40
43
  cell = sheet.add_cell(0, column_index, header_column)
41
44
  cell.change_fill(header_color)
45
+ if column_index == 0
46
+ add_hyperlink(sheet: sheet, cell: cell, to_sheet: 'change_logs', to_cell: 'A1')
47
+ end
48
+
49
+ if key = foreign_keys.detect { |k| k.options[:column] == header_column }
50
+ add_hyperlink(sheet: sheet, cell: cell, to_sheet: key.to_table, to_cell: 'A1')
51
+ end
42
52
  end
43
53
  end
44
54
 
@@ -81,12 +91,23 @@ module Breathing
81
91
  end
82
92
 
83
93
  change_logs.each.with_index(1) do |change_log, row_number|
84
- change_log.attributes_for_excel.each.with_index do |(_column_name, value), column_index|
85
- sheet.add_cell(row_number, column_index, value)
94
+ change_log.attributes_for_excel.each.with_index do |(column_name, value), column_index|
95
+ cell = sheet.add_cell(row_number, column_index, value)
96
+
97
+ if column_name == 'table_name'
98
+ add_hyperlink(sheet: sheet, cell: cell, to_sheet: value, to_cell: 'A1')
99
+ end
86
100
  end
87
101
  end
88
102
 
89
103
  add_style(sheet)
90
104
  end
105
+
106
+ def add_hyperlink(sheet:, cell:, to_sheet:, to_cell:)
107
+ sheet.hyperlinks ||= RubyXL::Hyperlinks.new
108
+ sheet.hyperlinks << RubyXL::Hyperlink.new(ref: RubyXL::Reference.ind2ref(cell.row, cell.column), location: "#{to_sheet}!#{to_cell}")
109
+ cell.change_font_underline(true)
110
+ cell.change_font_color('1F1FFF') # blue
111
+ end
91
112
  end
92
113
  end
data/spec/app.rb CHANGED
@@ -7,6 +7,7 @@ ActiveRecord::Base.establish_connection(
7
7
 
8
8
  ActiveRecord::Schema.define version: 0 do
9
9
  create_table :users, force: true do |t|
10
+ t.references :department, foreign_key: false
10
11
  t.string :name, null: false
11
12
  t.integer :age, null: false
12
13
  t.timestamps null: false
@@ -16,6 +17,8 @@ ActiveRecord::Schema.define version: 0 do
16
17
  t.string :name, null: false
17
18
  t.timestamps null: false
18
19
  end
20
+
21
+ add_foreign_key :users, :departments
19
22
  end
20
23
 
21
24
  class User < ActiveRecord::Base
@@ -16,23 +16,24 @@ describe Breathing::Excel do
16
16
  Tempfile.open(['tmp', '.xlsx']) do |file|
17
17
  Breathing::Excel.new.create(file_name: file.path)
18
18
  workbook = RubyXL::Parser.parse(file.path)
19
- expect(workbook.sheets[0].name).to eq('users')
20
- user_sheet = workbook.worksheets[0]
19
+ expect(workbook.sheets.map(&:name)).to eq(%w[change_logs users])
20
+ user_sheet = workbook.worksheets.last
21
21
  expect(user_sheet.sheet_data.size).to eq(Breathing::ChangeLog.where(table_name: :users).count + 1)
22
22
  end
23
23
  end
24
24
 
25
25
  it 'multi sheets' do
26
- user = User.create!(name: 'a', age: 20)
26
+ department = Department.create!(name: 'a')
27
+
28
+ user = User.create!(name: 'a', age: 20, department_id: department.id)
27
29
  user.update!(age: 21)
28
30
  user.destroy!
29
- Department.create!(name: 'a')
30
31
 
31
32
  Tempfile.open(['tmp', '.xlsx']) do |file|
32
33
  Breathing::Excel.new.create(file_name: file.path)
33
34
  workbook = RubyXL::Parser.parse(file.path)
34
- expect(workbook.sheets.map(&:name)).to eq(%w[departments users change_logs])
35
- change_logs_sheet = workbook.worksheets.last
35
+ expect(workbook.sheets.map(&:name)).to eq(%w[change_logs departments users])
36
+ change_logs_sheet = workbook.worksheets.first
36
37
 
37
38
  expect(change_logs_sheet.sheet_data.size).to eq(Breathing::ChangeLog.count + 1)
38
39
  end
@@ -16,7 +16,7 @@ describe Breathing::TerminalTable do
16
16
  table = Breathing::TerminalTable.new(:users)
17
17
  puts table.render(id: 1)
18
18
 
19
- expect(table.rows.size).to eq(3)
19
+ expect(table.rows.size - 2).to eq(3) # Three rows excluding header rows
20
20
  end
21
21
  end
22
22
  end
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.9
4
+ version: 0.0.11
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-23 00:00:00.000000000 Z
11
+ date: 2023-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.0
33
+ version: 7.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.0
40
+ version: 7.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hairtrigger
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 3.4.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pry-byebug
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -177,14 +191,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - ">="
179
193
  - !ruby/object:Gem::Version
180
- version: '0'
194
+ version: '3.0'
181
195
  required_rubygems_version: !ruby/object:Gem::Requirement
182
196
  requirements:
183
197
  - - ">="
184
198
  - !ruby/object:Gem::Version
185
199
  version: '0'
186
200
  requirements: []
187
- rubygems_version: 3.0.3
201
+ rubygems_version: 3.4.22
188
202
  signing_key:
189
203
  specification_version: 4
190
204
  summary: Audit logging for database