rails-crud-tools 0.4.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6550332d57eaa6efc9a533edcd245dc0fbb622f3db4dc60137ded1ce07b9732f
4
- data.tar.gz: d640cad53acee4a59aaf354dec8c0fee9b80c51112f3240814c34205288a2ef7
3
+ metadata.gz: '008fdf2673bcbae231ccc376ca9fdf1c7647ea2df3a3a5037e6beb60d4b67728'
4
+ data.tar.gz: c8006b6be02b313626f05cf021a3264a555ed54314f60c3e349aabdc680e28b4
5
5
  SHA512:
6
- metadata.gz: a54979463a9fc47dc5da2e932b94f82e0c992b19ea59b4107d56f55cd88fc5426beaea58042b7c693c305e3a4aa9856afacf239c96acb990af13557e94eba0ea
7
- data.tar.gz: 8e2638a585a23d084a7c9e1347138604d0f65aa33e680af4aa93c2e216f345ce80037335e502617a8ce78698aa2a168517dffc11a996901753caa42d384dbba6
6
+ metadata.gz: 5f7b3dd252dad14b4e262d33e6f7c79fb784e791739ba0d74adb33fb6187f473d84d314c342f897ea97670b215bd8811a36195b070642252990f9f26d6adb142
7
+ data.tar.gz: fe6df88290d5132775d2e796e9a2b80f01ec3409f5ffc1b7c9438b4993f16681bd5e4c06e63cc91d46e4b31f8f5a8f8e7c707d9acfbde428d4f3faa4637773a5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
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
+
1
5
  ## [0.4.2] - 2025-01-06
2
6
  - Fixed to update the last modifier of the CRUD file
3
7
  - 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
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ ENV["SKIP_CRUD_SETUP"] = "true"
2
3
  require "rails/crud/tools/cli"
3
4
 
4
5
  def display_help
@@ -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.debug "last modified by: #{last_modified_by}. process_id: #{process_id}"
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
- config = CrudConfig.instance
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
- # INSERT, UPDATE, DELETE, SELECT のみを対象とする
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
- private
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: method=#{method}, key=#{key}"
69
73
  return nil
70
74
  end
71
75
 
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Crud
5
5
  module Tools
6
- VERSION = "0.4.2"
6
+ VERSION = "0.4.3"
7
7
  end
8
8
  end
9
9
  end
@@ -29,7 +29,7 @@ module Rails
29
29
  setup_notifications
30
30
  end
31
31
 
32
- setup
32
+ setup unless ENV["SKIP_CRUD_SETUP"] == "true"
33
33
  end
34
34
  end
35
35
  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.4.2
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-05 00:00:00.000000000 Z
11
+ date: 2025-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord