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 +4 -4
- data/.rubocop.yml +6 -1
- data/CHANGELOG.md +7 -0
- data/README.md +11 -0
- data/lib/rails/crud/tools/crud_data.rb +17 -8
- data/lib/rails/crud/tools/crud_operations_logger.rb +40 -21
- data/lib/rails/crud/tools/version.rb +1 -1
- 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: e8c8fe1e3590b9f9d338def25a4a4202854cb744950119a4ca58b809bcc33d77
|
4
|
+
data.tar.gz: baca515de9005597ae4664b317812c57558d5ef33991bacceb85c3bb7df313f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f59fb3f51760b34b527a92263f68ee54d1698f66836875027903a147dfe0e2e16553b3c62c2ba1ed7ae35c72e3f2c2e731597b177956ae5aae041d68632eafa8
|
7
|
+
data.tar.gz: e9c6cf57f1f8dfab373e98d6364df3b421b5f609e599a8bbf141f4a1c41b025c28f8891933c10a4f960c71c2e54db65a40c9ca2369939e7292def391bd3776bc
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
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
|
-
|
82
|
+
CrudLogger.logger.debug "Starting to read ZIP file: #{file_path}"
|
83
|
+
CrudLogger.logger.debug "File size: #{File.size(file_path)}"
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2025-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|