rails-crud-tools 0.4.0 → 0.4.2

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: 768af8c4b3d9581a61568c0817ae477ef8d2f30552825ba1c69fa7daa4d748dc
4
- data.tar.gz: aab060f00958cfa1c1969f7bb87692854b8a5c6d638cc7b31b4c540b6071e871
3
+ metadata.gz: 6550332d57eaa6efc9a533edcd245dc0fbb622f3db4dc60137ded1ce07b9732f
4
+ data.tar.gz: d640cad53acee4a59aaf354dec8c0fee9b80c51112f3240814c34205288a2ef7
5
5
  SHA512:
6
- metadata.gz: 0e58858f11d6fa4aab47fa791881ee52e2d714f347abee711eaeedfd57f780f51c63f0f8fae3964eb897b454e93fe116a0fb1cbcf57892d5f22612b3e7bd5500
7
- data.tar.gz: 96a3967933bf721e59d1007a2fe12a3103f52866197401436523355282cc72367417c62a462b9490395b0f8ade376b8d8988b574df0178edb1ba012668085193
6
+ metadata.gz: a54979463a9fc47dc5da2e932b94f82e0c992b19ea59b4107d56f55cd88fc5426beaea58042b7c693c305e3a4aa9856afacf239c96acb990af13557e94eba0ea
7
+ data.tar.gz: 8e2638a585a23d084a7c9e1347138604d0f65aa33e680af4aa93c2e216f345ce80037335e502617a8ce78698aa2a168517dffc11a996901753caa42d384dbba6
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,61 +1,55 @@
1
- ## [0.4.0] - 2025-01-03
2
- - セルの値が変化する場合のみ保存するよう修正
3
- - 設定ファイルにシート名を追加
4
- - 設定ファイルにフォント名を追加
5
- - テストコード作成
6
- - 初期化コマンド追加
7
- - 設定ファイル作成コマンド追加
1
+ ## [0.4.2] - 2025-01-06
2
+ - Fixed to update the last modifier of the CRUD file
3
+ - Changed CRUD file saving process to asynchronous processing
8
4
 
9
- ## [0.3.2] - 2025-01-01
5
+ ## [0.4.1] - 2025-01-04
6
+ - Create the base directory if it does not exist during initialization
10
7
 
11
- - 複数スレッド対応
8
+ ## [0.4.0] - 2025-01-04
9
+ - Fixed to save only when cell values change
10
+ - Added sheet name to configuration file
11
+ - Added font name to configuration file
12
+ - Created test code
13
+ - Added initialization command
14
+ - Added configuration file creation command
12
15
 
13
- ## [0.3.1] - 2024-12-31
16
+ ## [0.3.2] - 2025-01-01
17
+ - Multi-thread support
14
18
 
15
- - rails-crud-toolsに変更
19
+ ## [0.3.1] - 2024-12-31
20
+ - Changed to rails-crud-tools
16
21
 
17
22
  ## [0.3.0] - 2024-12-30
18
-
19
- - ジョブ対応
20
- - クラッド図生成コマンドの追加
23
+ - Job support
24
+ - Added command to generate CRUD diagrams
21
25
 
22
26
  ## [0.2.2] - 2024-12-25
23
-
24
- - SQL出力のON/OFFを追加
25
- - サマリーログの改善
27
+ - Added ON/OFF for SQL output
28
+ - Improved summary log
26
29
 
27
30
  ## [0.2.1] - 2024-12-25
28
-
29
- - リファクタリング
31
+ - Refactoring
30
32
 
31
33
  ## [0.2.0] - 2024-12-25
32
-
33
- - api対応
34
+ - API support
34
35
 
35
36
  ## [0.1.6] - 2024-12-25
36
-
37
- - ログ改善
37
+ - Improved logging
38
38
 
39
39
  ## [0.1.5] - 2024-12-25
40
-
41
- - マルチスレッド改善
40
+ - Improved multi-threading
42
41
 
43
42
  ## [0.1.4] - 2024-12-24
44
-
45
- - リファクタリング
43
+ - Refactoring
46
44
 
47
45
  ## [0.1.3] - 2024-12-24
48
-
49
- - bug fix
46
+ - Bug fix
50
47
 
51
48
  ## [0.1.2] - 2024-12-24
52
-
53
- - bug fix
49
+ - Bug fix
54
50
 
55
51
  ## [0.1.1] - 2024-12-24
56
-
57
- - プレビュー版のリリース
52
+ - Preview release
58
53
 
59
54
  ## [0.1.0] - 2024-12-23
60
-
61
- - Initial release
55
+ - 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
@@ -9,7 +9,7 @@ It simplifies logging and managing CRUD operations seamlessly within a Rails app
9
9
  Add the gem to the `development` group in your application's Gemfile by including the following lines:
10
10
 
11
11
  ```ruby
12
- gem 'rails-crud-tools', git: 'https://github.com/YamabikoLab/rails-crud-tools', tag: 'v*.*.*'
12
+ gem 'rails-crud-tools'
13
13
  ```
14
14
 
15
15
  Then execute:
@@ -111,6 +111,10 @@ module RailsCrudTools
111
111
 
112
112
  # ファイルを保存
113
113
  crud_file = config.crud_file_path
114
+ base_dir = File.dirname(crud_file)
115
+
116
+ # base_dirが存在しなければ作成
117
+ FileUtils.mkdir_p(base_dir) unless Dir.exist?(base_dir)
114
118
  workbook.write(crud_file)
115
119
 
116
120
  puts "Output: #{crud_file}"
@@ -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.debug "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シートを取得する
@@ -65,7 +65,7 @@ module Rails
65
65
  key = sidekiq_job_class
66
66
  method = Constants::DEFAULT_METHOD
67
67
  else
68
- CrudLogger.logger.warn "Unknown method and key detected"
68
+ CrudLogger.logger.warn "Unknown method and key detected: method=#{method}, key=#{key}"
69
69
  return nil
70
70
  end
71
71
 
@@ -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
+ CrudLogger.logger.debug "Updated timestamp: #{timestamp}"
156
+ # タイムスタンプを更新する
157
+ CrudData.instance.last_loaded_time = 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.0"
6
+ VERSION = "0.4.2"
7
7
  end
8
8
  end
9
9
  end
@@ -24,6 +24,7 @@ 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
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.0
4
+ version: 0.4.2
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-05 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
  - - ">="