rails-crud-tools 0.4.1 → 0.4.3
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 +1 -1
- data/CHANGELOG.md +30 -35
- data/Gemfile +5 -4
- data/README.md +1 -1
- data/exe/crud +1 -0
- data/lib/rails/crud/tools/crud_data.rb +24 -1
- data/lib/rails/crud/tools/crud_notifications.rb +36 -32
- data/lib/rails/crud/tools/crud_operations_logger.rb +54 -9
- data/lib/rails/crud/tools/version.rb +1 -1
- data/lib/rails/crud/tools.rb +2 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '008fdf2673bcbae231ccc376ca9fdf1c7647ea2df3a3a5037e6beb60d4b67728'
|
4
|
+
data.tar.gz: c8006b6be02b313626f05cf021a3264a555ed54314f60c3e349aabdc680e28b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f7b3dd252dad14b4e262d33e6f7c79fb784e791739ba0d74adb33fb6187f473d84d314c342f897ea97670b215bd8811a36195b070642252990f9f26d6adb142
|
7
|
+
data.tar.gz: fe6df88290d5132775d2e796e9a2b80f01ec3409f5ffc1b7c9438b4993f16681bd5e4c06e63cc91d46e4b31f8f5a8f8e7c707d9acfbde428d4f3faa4637773a5
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,64 +1,59 @@
|
|
1
|
+
## [0.4.3] - 2025-01-07
|
2
|
+
- Refactored `crud_notifications.rb`.
|
3
|
+
- Modified to not execute the `setup` method in `tools.rb` when running commands.
|
4
|
+
|
5
|
+
## [0.4.2] - 2025-01-06
|
6
|
+
- Fixed to update the last modifier of the CRUD file
|
7
|
+
- Changed CRUD file saving process to asynchronous processing
|
8
|
+
|
1
9
|
## [0.4.1] - 2025-01-04
|
2
|
-
-
|
10
|
+
- Create the base directory if it does not exist during initialization
|
3
11
|
|
4
12
|
## [0.4.0] - 2025-01-04
|
5
|
-
-
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
13
|
+
- Fixed to save only when cell values change
|
14
|
+
- Added sheet name to configuration file
|
15
|
+
- Added font name to configuration file
|
16
|
+
- Created test code
|
17
|
+
- Added initialization command
|
18
|
+
- Added configuration file creation command
|
11
19
|
|
12
20
|
## [0.3.2] - 2025-01-01
|
13
|
-
|
14
|
-
- 複数スレッド対応
|
21
|
+
- Multi-thread support
|
15
22
|
|
16
23
|
## [0.3.1] - 2024-12-31
|
17
|
-
|
18
|
-
- rails-crud-toolsに変更
|
24
|
+
- Changed to rails-crud-tools
|
19
25
|
|
20
26
|
## [0.3.0] - 2024-12-30
|
21
|
-
|
22
|
-
-
|
23
|
-
- クラッド図生成コマンドの追加
|
27
|
+
- Job support
|
28
|
+
- Added command to generate CRUD diagrams
|
24
29
|
|
25
30
|
## [0.2.2] - 2024-12-25
|
26
|
-
|
27
|
-
-
|
28
|
-
- サマリーログの改善
|
31
|
+
- Added ON/OFF for SQL output
|
32
|
+
- Improved summary log
|
29
33
|
|
30
34
|
## [0.2.1] - 2024-12-25
|
31
|
-
|
32
|
-
- リファクタリング
|
35
|
+
- Refactoring
|
33
36
|
|
34
37
|
## [0.2.0] - 2024-12-25
|
35
|
-
|
36
|
-
- api対応
|
38
|
+
- API support
|
37
39
|
|
38
40
|
## [0.1.6] - 2024-12-25
|
39
|
-
|
40
|
-
- ログ改善
|
41
|
+
- Improved logging
|
41
42
|
|
42
43
|
## [0.1.5] - 2024-12-25
|
43
|
-
|
44
|
-
- マルチスレッド改善
|
44
|
+
- Improved multi-threading
|
45
45
|
|
46
46
|
## [0.1.4] - 2024-12-24
|
47
|
-
|
48
|
-
- リファクタリング
|
47
|
+
- Refactoring
|
49
48
|
|
50
49
|
## [0.1.3] - 2024-12-24
|
51
|
-
|
52
|
-
- bug fix
|
50
|
+
- Bug fix
|
53
51
|
|
54
52
|
## [0.1.2] - 2024-12-24
|
55
|
-
|
56
|
-
- bug fix
|
53
|
+
- Bug fix
|
57
54
|
|
58
55
|
## [0.1.1] - 2024-12-24
|
59
|
-
|
60
|
-
- プレビュー版のリリース
|
56
|
+
- Preview release
|
61
57
|
|
62
58
|
## [0.1.0] - 2024-12-23
|
63
|
-
|
64
|
-
- Initial release
|
59
|
+
- Initial release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -65,7 +65,7 @@ This workbook contains macros that help in managing and visualizing CRUD operati
|
|
65
65
|
|
66
66
|
You can download the `crud_macro.xlsm` file from the following link:
|
67
67
|
|
68
|
-
[Download crud_macro.xlsm](https://github.com/YamabikoLab/rails-crud/raw/main/tools/crud_macro.xlsm)
|
68
|
+
[Download crud_macro.xlsm](https://github.com/YamabikoLab/rails-crud-tools/raw/main/tools/crud_macro.xlsm)
|
69
69
|
|
70
70
|
## Development
|
71
71
|
|
data/exe/crud
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "zip"
|
1
2
|
require_relative "crud_logger"
|
2
3
|
require_relative "constants"
|
3
4
|
|
@@ -8,9 +9,10 @@ module Rails
|
|
8
9
|
class CrudData
|
9
10
|
include Singleton
|
10
11
|
|
11
|
-
attr_accessor :crud_rows, :crud_cols, :workbook, :last_loaded_time
|
12
|
+
attr_accessor :process_id, :crud_rows, :crud_cols, :workbook, :last_loaded_time
|
12
13
|
|
13
14
|
def initialize
|
15
|
+
@process_id = nil
|
14
16
|
@crud_rows = {}
|
15
17
|
@crud_cols = {}
|
16
18
|
@last_loaded_time = nil
|
@@ -61,9 +63,30 @@ module Rails
|
|
61
63
|
return unless config.enabled
|
62
64
|
|
63
65
|
return unless @last_loaded_time.nil? || File.mtime(config.crud_file_path) > @last_loaded_time
|
66
|
+
|
67
|
+
last_modified_by = get_last_modified_by(config.crud_file_path)
|
68
|
+
CrudLogger.logger.info "last modified by: #{last_modified_by}. process_id: #{process_id}"
|
69
|
+
return if process_id == last_modified_by
|
70
|
+
|
64
71
|
CrudLogger.logger.info "Reloading CRUD data due to file modification. last_loaded_time = #{@last_loaded_time}"
|
65
72
|
load_crud_data
|
73
|
+
end
|
74
|
+
|
75
|
+
# xlsxファイルの最終更新者を取得する
|
76
|
+
def get_last_modified_by(file_path)
|
77
|
+
last_modified_by = nil
|
78
|
+
|
79
|
+
Zip::File.open(file_path) do |zipfile|
|
80
|
+
doc_props = zipfile.find_entry("docProps/core.xml")
|
81
|
+
if doc_props
|
82
|
+
content = doc_props.get_input_stream.read
|
83
|
+
last_modified_by = content[/\<cp:lastModifiedBy\>(.*?)\<\/cp:lastModifiedBy\>/, 1]
|
84
|
+
else
|
85
|
+
CrudLogger.logger.warn "docProps/core.xml が見つかりませんでした。"
|
86
|
+
end
|
87
|
+
end
|
66
88
|
|
89
|
+
last_modified_by
|
67
90
|
end
|
68
91
|
|
69
92
|
# CRUDシートを取得する
|
@@ -10,38 +10,10 @@ module Rails
|
|
10
10
|
# 既に通知が登録されている場合は処理を中断
|
11
11
|
return if @subscribed
|
12
12
|
|
13
|
-
|
14
|
-
if config.enabled
|
13
|
+
if CrudConfig.instance.enabled
|
15
14
|
# SQL クエリを監視する
|
16
15
|
ActiveSupport::Notifications.subscribe(/sql.active_record/) do |name, started, finished, unique_id, data|
|
17
|
-
|
18
|
-
if data[:sql] =~ /(INSERT|UPDATE|DELETE|SELECT)/
|
19
|
-
operation = case $1
|
20
|
-
when "INSERT" then "C"
|
21
|
-
when "UPDATE" then "U"
|
22
|
-
when "DELETE" then "D"
|
23
|
-
when "SELECT" then "R"
|
24
|
-
else "Unknown"
|
25
|
-
end
|
26
|
-
|
27
|
-
match_data = data[:sql].match(/(?:INSERT INTO|UPDATE|DELETE FROM|FROM)\s+`?(\w+)`?/i)
|
28
|
-
if match_data
|
29
|
-
# テーブル名を取得して CRUD 操作に追加
|
30
|
-
table_name = match_data[1]
|
31
|
-
key, method = determine_key_and_method
|
32
|
-
next if key.nil? || method.nil?
|
33
|
-
|
34
|
-
CrudOperations.instance.add_operation(method, key, table_name, operation)
|
35
|
-
|
36
|
-
next unless config.sql_logging_enabled
|
37
|
-
|
38
|
-
# SQL ログを出力
|
39
|
-
CrudLogger.logger.info "#{data[:name]} - #{data[:sql]}"
|
40
|
-
else
|
41
|
-
# テーブル名が見つからない場合は警告を出力
|
42
|
-
CrudLogger.logger.warn "Table name not found in SQL: #{data[:sql]}"
|
43
|
-
end
|
44
|
-
end
|
16
|
+
process_sql(data)
|
45
17
|
end
|
46
18
|
end
|
47
19
|
|
@@ -49,7 +21,40 @@ module Rails
|
|
49
21
|
@subscribed = true
|
50
22
|
end
|
51
23
|
|
52
|
-
|
24
|
+
def self.process_sql(data)
|
25
|
+
return unless data[:sql] =~ /(INSERT|UPDATE|DELETE|SELECT)/
|
26
|
+
|
27
|
+
operation = case ::Regexp.last_match(1)
|
28
|
+
when "INSERT" then "C"
|
29
|
+
when "SELECT" then "R"
|
30
|
+
when "UPDATE" then "U"
|
31
|
+
when "DELETE" then "D"
|
32
|
+
else "Unknown"
|
33
|
+
end
|
34
|
+
|
35
|
+
match_data = data[:sql].match(/(?:INSERT INTO|UPDATE|DELETE FROM|FROM)\s+`?(\w+)`?/i)
|
36
|
+
unless match_data
|
37
|
+
# テーブル名が見つからない場合は警告を出力
|
38
|
+
CrudLogger.logger.warn "Table name not found in SQL: #{data[:sql]}"
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
# テーブル名を取得して CRUD 操作に追加
|
43
|
+
table_name = match_data[1]
|
44
|
+
key, method = determine_key_and_method
|
45
|
+
if key.nil? || method.nil?
|
46
|
+
CrudLogger.logger.warn "Request not found. #{data[:name]} - #{data[:sql]}"
|
47
|
+
return
|
48
|
+
end
|
49
|
+
|
50
|
+
CrudOperations.instance.add_operation(method, key, table_name, operation)
|
51
|
+
|
52
|
+
return unless CrudConfig.instance.sql_logging_enabled
|
53
|
+
|
54
|
+
# SQL ログを出力
|
55
|
+
CrudLogger.logger.info "#{data[:name]} - #{data[:sql]}"
|
56
|
+
|
57
|
+
end
|
53
58
|
|
54
59
|
# キーとメソッドを決定する
|
55
60
|
def self.determine_key_and_method
|
@@ -65,7 +70,6 @@ module Rails
|
|
65
70
|
key = sidekiq_job_class
|
66
71
|
method = Constants::DEFAULT_METHOD
|
67
72
|
else
|
68
|
-
CrudLogger.logger.warn "Unknown method and key detected"
|
69
73
|
return nil
|
70
74
|
end
|
71
75
|
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
require_relative
|
1
|
+
require "zip"
|
2
|
+
require_relative "crud_logger"
|
3
|
+
require_relative "constants"
|
3
4
|
|
4
5
|
# ログ出力を行うモジュール
|
5
6
|
module Rails
|
@@ -50,6 +51,31 @@ module Rails
|
|
50
51
|
Thread.current[:crud_sidekiq_job_class] = nil
|
51
52
|
end
|
52
53
|
|
54
|
+
# xlsxファイルの最終更新者を更新する
|
55
|
+
def set_last_modified_by(file_path, modifier_name)
|
56
|
+
Zip::File.open(file_path) do |zip_file|
|
57
|
+
doc_props = zip_file.find_entry("docProps/core.xml")
|
58
|
+
if doc_props
|
59
|
+
content = doc_props.get_input_stream.read
|
60
|
+
updated_content = if content.include?("<cp:lastModifiedBy>")
|
61
|
+
content.sub(
|
62
|
+
%r{<cp:lastModifiedBy>.*?</cp:lastModifiedBy>},
|
63
|
+
"<cp:lastModifiedBy>#{modifier_name}</cp:lastModifiedBy>"
|
64
|
+
)
|
65
|
+
else
|
66
|
+
content.sub(
|
67
|
+
%r{</cp:coreProperties>},
|
68
|
+
"<cp:lastModifiedBy>#{modifier_name}</cp:lastModifiedBy></cp:coreProperties>"
|
69
|
+
)
|
70
|
+
end
|
71
|
+
zip_file.get_output_stream("docProps/core.xml") { |f| f.write(updated_content) }
|
72
|
+
CrudLogger.logger.info "Set the last modifier to #{modifier_name}."
|
73
|
+
else
|
74
|
+
CrudLogger.logger.warn "docProps/core.xml was not found."
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
53
79
|
private
|
54
80
|
|
55
81
|
# リクエストの詳細をログ出力する
|
@@ -107,15 +133,34 @@ module Rails
|
|
107
133
|
end
|
108
134
|
end
|
109
135
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
#
|
116
|
-
|
136
|
+
return unless contents_changed
|
137
|
+
|
138
|
+
Thread.new do
|
139
|
+
update_crud_file
|
140
|
+
rescue StandardError => e
|
141
|
+
CrudLogger.logger.error "Failed to update #{CrudConfig.instance.crud_file_path}: #{e.message}"
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
def update_crud_file
|
148
|
+
File.open(CrudConfig.instance.crud_file_path, "r+") do |crud_file|
|
149
|
+
crud_file.flock(File::LOCK_EX)
|
150
|
+
begin
|
151
|
+
# Excelファイルを書き込む
|
152
|
+
CrudData.instance.workbook.write(crud_file)
|
153
|
+
set_last_modified_by(crud_file, CrudData.instance.process_id)
|
154
|
+
timestamp = File.mtime(crud_file)
|
155
|
+
# タイムスタンプを更新する
|
156
|
+
CrudData.instance.last_loaded_time = timestamp
|
157
|
+
CrudLogger.logger.info "Updated timestamp: #{timestamp}"
|
158
|
+
ensure
|
159
|
+
crud_file.flock(File::LOCK_UN)
|
160
|
+
end
|
117
161
|
end
|
118
162
|
end
|
163
|
+
|
119
164
|
end
|
120
165
|
end
|
121
166
|
end
|
data/lib/rails/crud/tools.rb
CHANGED
@@ -24,11 +24,12 @@ module Rails
|
|
24
24
|
return
|
25
25
|
end
|
26
26
|
|
27
|
+
CrudData.instance.process_id = "rails-crud-tools-#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
27
28
|
CrudData.instance.load_crud_data
|
28
29
|
setup_notifications
|
29
30
|
end
|
30
31
|
|
31
|
-
setup
|
32
|
+
setup unless ENV["SKIP_CRUD_SETUP"] == "true"
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-crud-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
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-
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rubyXL
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,19 +39,19 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '3.4'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: rubyzip
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '2.4'
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '2.4'
|
41
55
|
description: This gem provides CRUD functionality for Rails applications.
|
42
56
|
email:
|
43
57
|
- yhijikata@systemlancer.com
|
@@ -89,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
103
|
requirements:
|
90
104
|
- - ">="
|
91
105
|
- !ruby/object:Gem::Version
|
92
|
-
version: 2.
|
106
|
+
version: 2.7.0
|
93
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
109
|
- - ">="
|