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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b9780c9345c5eb0ec2a7647681dac9a64b57194db6ef5fa4bd8ee92788b05fd
4
- data.tar.gz: 708d9395be78f1e80cebc09d9cc24df79d24d3dd731ff72b528ce2e7b0376ba7
3
+ metadata.gz: '008fdf2673bcbae231ccc376ca9fdf1c7647ea2df3a3a5037e6beb60d4b67728'
4
+ data.tar.gz: c8006b6be02b313626f05cf021a3264a555ed54314f60c3e349aabdc680e28b4
5
5
  SHA512:
6
- metadata.gz: 219063db88019b029890b3263d33569b96e771fe7e01c65631d07a12fdb12ac7151ef90a3c7a631c161b66e407f2a5e2d21731f25ae783d52918b78e8a34e34f
7
- data.tar.gz: cf01b00c5edf43220459ef19175f693acb0828d67c036b45a2996912397647d616365bda53d28f024c6c9fd2a54a379fd59127d6c0744296e943a02c4c1210ba
6
+ metadata.gz: 5f7b3dd252dad14b4e262d33e6f7c79fb784e791739ba0d74adb33fb6187f473d84d314c342f897ea97670b215bd8811a36195b070642252990f9f26d6adb142
7
+ data.tar.gz: fe6df88290d5132775d2e796e9a2b80f01ec3409f5ffc1b7c9438b4993f16681bd5e4c06e63cc91d46e4b31f8f5a8f8e7c707d9acfbde428d4f3faa4637773a5
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
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
- - SQL出力のON/OFFを追加
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
@@ -11,7 +11,8 @@ gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
13
 
14
- group :test do
15
- gem "rails"
16
- gem "simplecov"
17
- end
14
+ gem "rubyzip", "~> 2.4"
15
+
16
+ gem "rails"
17
+
18
+ gem "simplecov"
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
@@ -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
- 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"
69
73
  return nil
70
74
  end
71
75
 
@@ -1,5 +1,6 @@
1
- require_relative 'crud_logger'
2
- require_relative 'constants'
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
- if contents_changed
111
- # Excelファイルを書き込む
112
- CrudData.instance.workbook.write(CrudConfig.instance.crud_file_path)
113
- timestamp = File.mtime(CrudConfig.instance.crud_file_path)
114
- CrudLogger.logger.debug "Updated timestamp: #{timestamp}"
115
- # タイムスタンプを更新する
116
- CrudData.instance.last_loaded_time = timestamp
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
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Crud
5
5
  module Tools
6
- VERSION = "0.4.1"
6
+ VERSION = "0.4.3"
7
7
  end
8
8
  end
9
9
  end
@@ -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.1
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-04 00:00:00.000000000 Z
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: activerecord
42
+ name: rubyzip
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '7.0'
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: '7.0'
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.6.0
106
+ version: 2.7.0
93
107
  required_rubygems_version: !ruby/object:Gem::Requirement
94
108
  requirements:
95
109
  - - ">="