rails-crud-tools 0.4.2 → 0.5.0
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/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/exe/crud +1 -0
- data/lib/rails/crud/tools/crud_data.rb +1 -1
- data/lib/rails/crud/tools/crud_notifications.rb +37 -32
- data/lib/rails/crud/tools/crud_operations_logger.rb +1 -1
- data/lib/rails/crud/tools/version.rb +1 -1
- data/lib/rails/crud/tools.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: b5f67e7e466a9b26e7ddf8a539d276694c0ad188117fc6b6719739b923a3577e
|
4
|
+
data.tar.gz: e684b41c0054a02162343721f290e3c77bd5d73a48302faed1858716a4c14fa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7dbb6a30981ee535a3656a80e88281d899d0b4271580e2920aedf670bfa846a2a4c0f4cb739a31ff016cb763bf6a491ceae34125a4b69b4885135b408a59091
|
7
|
+
data.tar.gz: db890338796f0430d4502a198c8f9ecb54184188b189ecdbefc4a4cb194b61761ca4c68e4e949cdff1801ecab103af135ffd918ad76439edb9f0c7b3365a75a8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.5.0] - 2025-01-07
|
2
|
+
- Multiple table support
|
3
|
+
|
4
|
+
## [0.4.3] - 2025-01-07
|
5
|
+
- Refactored `crud_notifications.rb`.
|
6
|
+
- Modified to not execute the `setup` method in `tools.rb` when running commands.
|
7
|
+
|
1
8
|
## [0.4.2] - 2025-01-06
|
2
9
|
- Fixed to update the last modifier of the CRUD file
|
3
10
|
- Changed CRUD file saving process to asynchronous processing
|
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
@@ -65,7 +65,7 @@ module Rails
|
|
65
65
|
return unless @last_loaded_time.nil? || File.mtime(config.crud_file_path) > @last_loaded_time
|
66
66
|
|
67
67
|
last_modified_by = get_last_modified_by(config.crud_file_path)
|
68
|
-
CrudLogger.logger.
|
68
|
+
CrudLogger.logger.info "last modified by: #{last_modified_by}. process_id: #{process_id}"
|
69
69
|
return if process_id == last_modified_by
|
70
70
|
|
71
71
|
CrudLogger.logger.info "Reloading CRUD data due to file modification. last_loaded_time = #{@last_loaded_time}"
|
@@ -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,41 @@ 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
|
+
table_names = data[:sql].scan(/(?:INSERT INTO|UPDATE|DELETE FROM|FROM|JOIN)\s+`?(\w+)`?(?:\s*,\s*`?(\w+)`?)*/i).flatten.compact
|
36
|
+
if table_names.empty?
|
37
|
+
# テーブル名が見つからない場合は警告を出力
|
38
|
+
CrudLogger.logger.warn "Table name not found in SQL: #{data[:sql]}"
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
key, method = determine_key_and_method
|
43
|
+
if key.nil? || method.nil?
|
44
|
+
CrudLogger.logger.warn "Request not found. #{data[:name]} - #{data[:sql]}"
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
# テーブル名を取得して CRUD 操作に追加
|
49
|
+
table_names.each do |table_name|
|
50
|
+
CrudOperations.instance.add_operation(method, key, table_name, operation)
|
51
|
+
end
|
52
|
+
|
53
|
+
return unless CrudConfig.instance.sql_logging_enabled
|
54
|
+
|
55
|
+
# SQL ログを出力
|
56
|
+
CrudLogger.logger.info "#{data[:name]} - #{data[:sql]}"
|
57
|
+
|
58
|
+
end
|
53
59
|
|
54
60
|
# キーとメソッドを決定する
|
55
61
|
def self.determine_key_and_method
|
@@ -65,7 +71,6 @@ module Rails
|
|
65
71
|
key = sidekiq_job_class
|
66
72
|
method = Constants::DEFAULT_METHOD
|
67
73
|
else
|
68
|
-
CrudLogger.logger.warn "Unknown method and key detected: method=#{method}, key=#{key}"
|
69
74
|
return nil
|
70
75
|
end
|
71
76
|
|
@@ -152,9 +152,9 @@ module Rails
|
|
152
152
|
CrudData.instance.workbook.write(crud_file)
|
153
153
|
set_last_modified_by(crud_file, CrudData.instance.process_id)
|
154
154
|
timestamp = File.mtime(crud_file)
|
155
|
-
CrudLogger.logger.debug "Updated timestamp: #{timestamp}"
|
156
155
|
# タイムスタンプを更新する
|
157
156
|
CrudData.instance.last_loaded_time = timestamp
|
157
|
+
CrudLogger.logger.info "Updated timestamp: #{timestamp}"
|
158
158
|
ensure
|
159
159
|
crud_file.flock(File::LOCK_UN)
|
160
160
|
end
|
data/lib/rails/crud/tools.rb
CHANGED
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.
|
4
|
+
version: 0.5.0
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|