rails-crud-tools 0.6.19 → 0.6.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 892dfb8bba908b09cde0be58f6df72ea071dc0370b261efc9642e1ed904006e7
4
- data.tar.gz: 347ab5a7c98f2e78d824319a7a683ee9401e9194edfe73642c44064d79b5ca58
3
+ metadata.gz: e8c8fe1e3590b9f9d338def25a4a4202854cb744950119a4ca58b809bcc33d77
4
+ data.tar.gz: baca515de9005597ae4664b317812c57558d5ef33991bacceb85c3bb7df313f6
5
5
  SHA512:
6
- metadata.gz: 5a52975a743403bda0b878094396fc0f5b515ec6140f71554f2837350b5df3b471ea9598ca2c3a5d662103a4575dddf6853a815742ca54834d8a6e14fa294f8b
7
- data.tar.gz: 435fbd9500a604ae449164b3444d6ee7930c5bd626fa8776a325118657f07b208ed78923da0e8a32d95cb29a5010a40ec0ab27dabe6d19b648e79b6d65af1791
6
+ metadata.gz: f59fb3f51760b34b527a92263f68ee54d1698f66836875027903a147dfe0e2e16553b3c62c2ba1ed7ae35c72e3f2c2e731597b177956ae5aae041d68632eafa8
7
+ data.tar.gz: e9c6cf57f1f8dfab373e98d6364df3b421b5f609e599a8bbf141f4a1c41b025c28f8891933c10a4f960c71c2e54db65a40c9ca2369939e7292def391bd3776bc
data/.rubocop.yml CHANGED
@@ -28,7 +28,12 @@ Metrics/PerceivedComplexity:
28
28
  Max: 20
29
29
 
30
30
  Metrics/ModuleLength:
31
- Max: 120
31
+ Max: 130
32
+
33
+ Metrics/BlockLength:
34
+ Enabled: true
35
+ Max: 30
36
+
32
37
  Gemspec/AddRuntimeDependency:
33
38
  Enabled: true
34
39
  Gemspec/DeprecatedAttributeAssignment:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.6.20] - 2025-02-05
2
+ - modified CRUD diagram is backed up on update
3
+ - made last updated thread-safe
4
+
5
+ ## [0.6.19] - 2025-01-30
6
+ - Bug fixes
7
+
1
8
  ## [0.6.11] - 2025-01-30
2
9
  - Bug fixes related to activesupport
3
10
 
data/README.md CHANGED
@@ -53,6 +53,17 @@ sql_logging_enabled: true # Enables or disables SQL logging for CRUD operations
53
53
  Once integrated, the gem automatically tracks CRUD operations (Create, Read, Update, Delete) performed in your application.
54
54
  The diagrams will update dynamically based on these operations, providing you with real-time insights into your application's data flow.
55
55
 
56
+ ### Automatic Backup
57
+
58
+ The gem automatically creates backup files when updating the CRUD diagram. When changes are made to the CRUD Excel file:
59
+
60
+ 1. A backup file is created with the `.bak` extension (e.g., `crud.xlsx.bak`)
61
+ 2. The backup is created before any modifications to the original file
62
+ 3. If an error occurs during the update, the backup file is used to restore the original file
63
+ 4. The backup file is automatically removed after a successful update
64
+
65
+ This ensures that your CRUD diagram data is protected against potential corruption or errors during updates.
66
+
56
67
  ## Logs
57
68
 
58
69
  Please refer to the log file at `log/crud.log`.
@@ -79,15 +79,24 @@ module Rails
79
79
 
80
80
  # xlsxファイルの最終更新者を取得する
81
81
  def get_last_modified_by(file_path)
82
- last_modified_by = nil
82
+ CrudLogger.logger.debug "Starting to read ZIP file: #{file_path}"
83
+ CrudLogger.logger.debug "File size: #{File.size(file_path)}"
83
84
 
84
- Zip::File.open(file_path) do |zipfile|
85
- doc_props = zipfile.find_entry("docProps/core.xml")
86
- if doc_props
87
- content = doc_props.get_input_stream.read
88
- last_modified_by = content[%r{<cp:lastModifiedBy>(.*?)</cp:lastModifiedBy>}, 1]
89
- else
90
- CrudLogger.logger.warn "docProps/core.xml が見つかりませんでした。"
85
+ last_modified_by = nil
86
+ File.open(file_path, "r") do |f|
87
+ f.flock(File::LOCK_SH)
88
+ begin
89
+ Zip::File.open(file_path) do |zipfile|
90
+ doc_props = zipfile.find_entry("docProps/core.xml")
91
+ if doc_props
92
+ content = doc_props.get_input_stream.read
93
+ last_modified_by = content[%r{<cp:lastModifiedBy>(.*?)</cp:lastModifiedBy>}, 1]
94
+ else
95
+ CrudLogger.logger.warn "docProps/core.xml が見つかりませんでした。"
96
+ end
97
+ end
98
+ ensure
99
+ f.flock(File::LOCK_UN)
91
100
  end
92
101
  end
93
102
 
@@ -3,6 +3,7 @@
3
3
  require "zip"
4
4
  require_relative "crud_logger"
5
5
  require_relative "constants"
6
+ require "fileutils"
6
7
 
7
8
  module Rails
8
9
  module Crud
@@ -55,25 +56,35 @@ module Rails
55
56
 
56
57
  # xlsxファイルの最終更新者を更新する
57
58
  def set_last_modified_by(file_path, modifier_name)
58
- Zip::File.open(file_path) do |zip_file|
59
- doc_props = zip_file.find_entry("docProps/core.xml")
60
- if doc_props
61
- content = doc_props.get_input_stream.read
62
- updated_content = if content.include?("<cp:lastModifiedBy>")
63
- content.sub(
64
- %r{<cp:lastModifiedBy>.*?</cp:lastModifiedBy>},
65
- "<cp:lastModifiedBy>#{modifier_name}</cp:lastModifiedBy>"
66
- )
67
- else
68
- content.sub(
69
- %r{</cp:coreProperties>},
70
- "<cp:lastModifiedBy>#{modifier_name}</cp:lastModifiedBy></cp:coreProperties>"
71
- )
72
- end
73
- zip_file.get_output_stream("docProps/core.xml") { |f| f.write(updated_content) }
74
- CrudLogger.logger.info "Set the last modifier to #{modifier_name}."
75
- else
76
- CrudLogger.logger.warn "docProps/core.xml was not found."
59
+ CrudLogger.logger.debug "Starting to read/write ZIP file: #{file_path}"
60
+ CrudLogger.logger.debug "File size: #{File.size(file_path)}"
61
+
62
+ File.open(file_path, "r+") do |f|
63
+ f.flock(File::LOCK_EX)
64
+ begin
65
+ Zip::File.open(file_path) do |zip_file|
66
+ doc_props = zip_file.find_entry("docProps/core.xml")
67
+ if doc_props
68
+ content = doc_props.get_input_stream.read
69
+ updated_content = if content.include?("<cp:lastModifiedBy>")
70
+ content.sub(
71
+ %r{<cp:lastModifiedBy>.*?</cp:lastModifiedBy>},
72
+ "<cp:lastModifiedBy>#{modifier_name}</cp:lastModifiedBy>"
73
+ )
74
+ else
75
+ content.sub(
76
+ %r{</cp:coreProperties>},
77
+ "<cp:lastModifiedBy>#{modifier_name}</cp:lastModifiedBy></cp:coreProperties>"
78
+ )
79
+ end
80
+ zip_file.get_output_stream("docProps/core.xml") { |f| f.write(updated_content) }
81
+ CrudLogger.logger.info "Set the last modifier to #{modifier_name}."
82
+ else
83
+ CrudLogger.logger.warn "docProps/core.xml was not found."
84
+ end
85
+ end
86
+ ensure
87
+ f.flock(File::LOCK_UN)
77
88
  end
78
89
  end
79
90
  end
@@ -140,17 +151,22 @@ module Rails
140
151
  Thread.new do
141
152
  update_crud_file
142
153
  rescue StandardError => e
143
- CrudLogger.logger.error "Failed to update #{CrudConfig.instance.config.crud_file_path}: #{e.message}"
154
+ CrudLogger.logger.error "Failed to update #{CrudConfig.instance.config.crud_file_path}: #{e.message}\n#{e.backtrace.join("\n")}"
144
155
  end
145
156
  end
146
157
 
147
158
  def update_crud_file
159
+ # バックアップを作成
160
+ if File.size(CrudConfig.instance.config.crud_file_path).positive?
161
+ backup_path = "#{CrudConfig.instance.config.crud_file_path}.bak"
162
+ FileUtils.cp(CrudConfig.instance.config.crud_file_path, backup_path)
163
+ end
164
+
148
165
  File.open(CrudConfig.instance.config.crud_file_path, "r+") do |crud_file|
149
166
  crud_file.flock(File::LOCK_EX)
150
167
  begin
151
168
  # Excelファイルを書き込む
152
169
  CrudData.instance.workbook.write(crud_file)
153
- set_last_modified_by(crud_file, CrudData.instance.process_id)
154
170
  timestamp = File.mtime(crud_file)
155
171
  # タイムスタンプを更新する
156
172
  CrudData.instance.last_loaded_time = timestamp
@@ -159,6 +175,9 @@ module Rails
159
175
  crud_file.flock(File::LOCK_UN)
160
176
  end
161
177
  end
178
+
179
+ # 最終更新者を設定
180
+ set_last_modified_by(CrudConfig.instance.config.crud_file_path, CrudData.instance.process_id)
162
181
  end
163
182
  end
164
183
  end
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Crud
5
5
  module Tools
6
- VERSION = "0.6.19"
6
+ VERSION = "0.6.20"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-crud-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.19
4
+ version: 0.6.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - yhijikata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-30 00:00:00.000000000 Z
11
+ date: 2025-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord