rails-crud-tools 0.6.0 → 0.6.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 +4 -4
- metadata +7 -35
- data/.rspec +0 -3
- data/.rubocop.yml +0 -13
- data/CHANGELOG.md +0 -65
- data/Dockerfile +0 -21
- data/Gemfile +0 -18
- data/LICENSE +0 -21
- data/LICENSE.txt +0 -21
- data/README.md +0 -108
- data/Rakefile +0 -12
- data/docker-compose.yml +0 -11
- data/exe/console +0 -15
- data/exe/crud +0 -28
- data/exe/setup +0 -8
- data/lib/rails/crud/tools/cli.rb +0 -182
- data/lib/rails/crud/tools/constants.rb +0 -9
- data/lib/rails/crud/tools/crud_config.rb +0 -50
- data/lib/rails/crud/tools/crud_data.rb +0 -103
- data/lib/rails/crud/tools/crud_logger.rb +0 -24
- data/lib/rails/crud/tools/crud_notifications.rb +0 -156
- data/lib/rails/crud/tools/crud_operations.rb +0 -50
- data/lib/rails/crud/tools/crud_operations_logger.rb +0 -167
- data/lib/rails/crud/tools/railtie.rb +0 -36
- data/lib/rails/crud/tools/version.rb +0 -9
- data/lib/rails/crud/tools.rb +0 -35
- data/sig/rails/crud.rbs +0 -6
- data/tools/crud_macro.xlsm +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc6f51b460ca246632e1ef6efa70234e1c2612a2df797a97db21a6609049f742
|
4
|
+
data.tar.gz: 8e894353f5f2b866e77eadb97d9d79f78c96118df5c85e05f1c4776b558e78cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbb6a0f8c47bc6828e832724cff92978688ba0545b7f87ebfc1d89708cc5feb56877663e5597fe27ef825d06e7c6326b3fa17ff21c981150c225ab87180acd2f
|
7
|
+
data.tar.gz: b35c525ba701ad3dc74683de8bd625952456e97406234833d4c89922e38b6249aacd861017849bd54520ac5bcc1fe021552b714d1e7b5ba7af5cc1087d651387
|
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.6.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -55,46 +55,18 @@ dependencies:
|
|
55
55
|
description: This gem provides CRUD functionality for Rails applications.
|
56
56
|
email:
|
57
57
|
- yhijikata@systemlancer.com
|
58
|
-
executables:
|
59
|
-
- console
|
60
|
-
- crud
|
61
|
-
- setup
|
58
|
+
executables: []
|
62
59
|
extensions: []
|
63
60
|
extra_rdoc_files: []
|
64
|
-
files:
|
65
|
-
|
66
|
-
- ".rubocop.yml"
|
67
|
-
- CHANGELOG.md
|
68
|
-
- Dockerfile
|
69
|
-
- Gemfile
|
70
|
-
- LICENSE
|
71
|
-
- LICENSE.txt
|
72
|
-
- README.md
|
73
|
-
- Rakefile
|
74
|
-
- docker-compose.yml
|
75
|
-
- exe/console
|
76
|
-
- exe/crud
|
77
|
-
- exe/setup
|
78
|
-
- lib/rails/crud/tools.rb
|
79
|
-
- lib/rails/crud/tools/cli.rb
|
80
|
-
- lib/rails/crud/tools/constants.rb
|
81
|
-
- lib/rails/crud/tools/crud_config.rb
|
82
|
-
- lib/rails/crud/tools/crud_data.rb
|
83
|
-
- lib/rails/crud/tools/crud_logger.rb
|
84
|
-
- lib/rails/crud/tools/crud_notifications.rb
|
85
|
-
- lib/rails/crud/tools/crud_operations.rb
|
86
|
-
- lib/rails/crud/tools/crud_operations_logger.rb
|
87
|
-
- lib/rails/crud/tools/railtie.rb
|
88
|
-
- lib/rails/crud/tools/version.rb
|
89
|
-
- sig/rails/crud.rbs
|
90
|
-
- tools/crud_macro.xlsm
|
91
|
-
homepage: https://github.com/YamabikoLab
|
61
|
+
files: []
|
62
|
+
homepage: https://github.com/YamabikoLab/rails-crud-tools
|
92
63
|
licenses:
|
93
64
|
- MIT
|
94
65
|
metadata:
|
95
|
-
homepage_uri: https://github.com/YamabikoLab
|
66
|
+
homepage_uri: https://github.com/YamabikoLab/rails-crud-tools
|
96
67
|
source_code_uri: https://github.com/YamabikoLab/rails-crud-tools
|
97
68
|
changelog_uri: https://github.com/YamabikoLab/rails-crud-tools/blob/main/CHANGELOG.md
|
69
|
+
rubygems_mfa_required: 'true'
|
98
70
|
post_install_message:
|
99
71
|
rdoc_options: []
|
100
72
|
require_paths:
|
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/CHANGELOG.md
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
## [0.6.0] - 2025-01-08
|
2
|
-
- Support for select insert, select update, and select delete
|
3
|
-
|
4
|
-
## [0.5.0] - 2025-01-07
|
5
|
-
- Multiple table support
|
6
|
-
|
7
|
-
## [0.4.3] - 2025-01-07
|
8
|
-
- Refactored `crud_notifications.rb`.
|
9
|
-
- Modified to not execute the `setup` method in `tools.rb` when running commands.
|
10
|
-
|
11
|
-
## [0.4.2] - 2025-01-06
|
12
|
-
- Fixed to update the last modifier of the CRUD file
|
13
|
-
- Changed CRUD file saving process to asynchronous processing
|
14
|
-
|
15
|
-
## [0.4.1] - 2025-01-04
|
16
|
-
- Create the base directory if it does not exist during initialization
|
17
|
-
|
18
|
-
## [0.4.0] - 2025-01-04
|
19
|
-
- Fixed to save only when cell values change
|
20
|
-
- Added sheet name to configuration file
|
21
|
-
- Added font name to configuration file
|
22
|
-
- Created test code
|
23
|
-
- Added initialization command
|
24
|
-
- Added configuration file creation command
|
25
|
-
|
26
|
-
## [0.3.2] - 2025-01-01
|
27
|
-
- Multi-thread support
|
28
|
-
|
29
|
-
## [0.3.1] - 2024-12-31
|
30
|
-
- Changed to rails-crud-tools
|
31
|
-
|
32
|
-
## [0.3.0] - 2024-12-30
|
33
|
-
- Job support
|
34
|
-
- Added command to generate CRUD diagrams
|
35
|
-
|
36
|
-
## [0.2.2] - 2024-12-25
|
37
|
-
- Added ON/OFF for SQL output
|
38
|
-
- Improved summary log
|
39
|
-
|
40
|
-
## [0.2.1] - 2024-12-25
|
41
|
-
- Refactoring
|
42
|
-
|
43
|
-
## [0.2.0] - 2024-12-25
|
44
|
-
- API support
|
45
|
-
|
46
|
-
## [0.1.6] - 2024-12-25
|
47
|
-
- Improved logging
|
48
|
-
|
49
|
-
## [0.1.5] - 2024-12-25
|
50
|
-
- Improved multi-threading
|
51
|
-
|
52
|
-
## [0.1.4] - 2024-12-24
|
53
|
-
- Refactoring
|
54
|
-
|
55
|
-
## [0.1.3] - 2024-12-24
|
56
|
-
- Bug fix
|
57
|
-
|
58
|
-
## [0.1.2] - 2024-12-24
|
59
|
-
- Bug fix
|
60
|
-
|
61
|
-
## [0.1.1] - 2024-12-24
|
62
|
-
- Preview release
|
63
|
-
|
64
|
-
## [0.1.0] - 2024-12-23
|
65
|
-
- Initial release
|
data/Dockerfile
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
FROM ruby:3.1.4
|
2
|
-
|
3
|
-
ARG IDEURL=https://download.jetbrains.com/ruby/RubyMine-2024.3.1.tar.gz
|
4
|
-
|
5
|
-
RUN apt-get update -qq && apt-get install -y \
|
6
|
-
build-essential \
|
7
|
-
vim && \
|
8
|
-
rm -rf /var/lib/apt/lists/*
|
9
|
-
|
10
|
-
ENV EDITOR=vim
|
11
|
-
|
12
|
-
WORKDIR /root/app
|
13
|
-
|
14
|
-
RUN curl -fsSL -o ide.tar.gz $IDEURL && \
|
15
|
-
mkdir ide && \
|
16
|
-
tar xfz ide.tar.gz --strip-components=1 -C ide && \
|
17
|
-
rm ide.tar.gz
|
18
|
-
|
19
|
-
CMD yes '' | ide/bin/remote-dev-server.sh run $APP_ROOT --listenOn 0.0.0.0 --port 5995
|
20
|
-
|
21
|
-
EXPOSE 5995
|
data/Gemfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in rails-crud-tools.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
|
-
gem "rspec", "~> 3.0"
|
11
|
-
|
12
|
-
gem "rubocop", "~> 1.21"
|
13
|
-
|
14
|
-
gem "rubyzip", "~> 2.4"
|
15
|
-
|
16
|
-
gem "rails"
|
17
|
-
|
18
|
-
gem "simplecov"
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2024 yamabiko
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2024 yhijikata
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
# Rails::Crud::Tools
|
2
|
-
|
3
|
-
Welcome to Rails::Crud::Tools!
|
4
|
-
This gem provides a tool to automatically update CRUD diagrams as you interact with your application.
|
5
|
-
It simplifies logging and managing CRUD operations seamlessly within a Rails application.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add the gem to the `development` group in your application's Gemfile by including the following lines:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'rails-crud-tools'
|
13
|
-
```
|
14
|
-
|
15
|
-
Then execute:
|
16
|
-
|
17
|
-
```sh
|
18
|
-
$ bundle install
|
19
|
-
```
|
20
|
-
|
21
|
-
If you are not using Bundler, you can install the gem manually:
|
22
|
-
|
23
|
-
```sh
|
24
|
-
$ gem install rails-crud-tools
|
25
|
-
```
|
26
|
-
|
27
|
-
## Usage
|
28
|
-
|
29
|
-
### Setup
|
30
|
-
This command will generate the **doc/crud.xlsx** file and the **.crudconfig** file.
|
31
|
-
|
32
|
-
```sh
|
33
|
-
$ bundle exec crud init
|
34
|
-
```
|
35
|
-
|
36
|
-
.crudconfig
|
37
|
-
```yaml
|
38
|
-
enabled: true # Enables or disables the CRUD tools functionality
|
39
|
-
base_dir: doc # The base directory where the CRUD files will be stored
|
40
|
-
crud_file: crud.xlsx # The name of the CRUD Excel file
|
41
|
-
sheet_name: CRUD # The name of the sheet in the CRUD Excel file
|
42
|
-
method_col: Verb # Column indicating the HTTP method
|
43
|
-
action_col: Controller#Action # Column indicating the controller and action
|
44
|
-
table_start_col: your_first_table # Column where the table starts
|
45
|
-
header_bg_color: 00FFCC # The background color for the header in the CRUD Excel file
|
46
|
-
sql_logging_enabled: true # Enables or disables SQL logging for CRUD operations
|
47
|
-
font_name: Arial # The font name used in the CRUD Excel file
|
48
|
-
```
|
49
|
-
|
50
|
-
### How It Works
|
51
|
-
|
52
|
-
Once integrated, the gem automatically tracks CRUD operations (Create, Read, Update, Delete) performed in your application.
|
53
|
-
The diagrams will update dynamically based on these operations, providing you with real-time insights into your application's data flow.
|
54
|
-
|
55
|
-
## Logs
|
56
|
-
|
57
|
-
Please refer to the log file at `log/crud.log`.
|
58
|
-
|
59
|
-
## CRUD Macro Workbook
|
60
|
-
|
61
|
-
The `tools/crud_macro.xlsm` file is a macro-enabled workbook used for manipulating CRUD diagrams.
|
62
|
-
This workbook contains macros that help in managing and visualizing CRUD operations within your application.
|
63
|
-
|
64
|
-
### Download
|
65
|
-
|
66
|
-
You can download the `crud_macro.xlsm` file from the following link:
|
67
|
-
|
68
|
-
[Download crud_macro.xlsm](https://github.com/YamabikoLab/rails-crud-tools/raw/main/tools/crud_macro.xlsm)
|
69
|
-
|
70
|
-
## Development
|
71
|
-
|
72
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run the following command to execute the tests:
|
73
|
-
|
74
|
-
```sh
|
75
|
-
$ rake spec
|
76
|
-
```
|
77
|
-
|
78
|
-
You can also use `bin/console` for an interactive prompt to experiment with the gem’s functionality.
|
79
|
-
|
80
|
-
To install this gem onto your local machine for development purposes, run:
|
81
|
-
|
82
|
-
```sh
|
83
|
-
$ bundle exec rake install
|
84
|
-
```
|
85
|
-
|
86
|
-
To release a new version:
|
87
|
-
1. Update the version number in `version.rb`.
|
88
|
-
2. Run:
|
89
|
-
|
90
|
-
```sh
|
91
|
-
$ bundle exec rake release
|
92
|
-
```
|
93
|
-
|
94
|
-
This will create a git tag for the new version, push the git commits and tag, and upload the `.gem` file to [RubyGems](https://rubygems.org).
|
95
|
-
|
96
|
-
## Contributing
|
97
|
-
|
98
|
-
Bug reports and pull requests are welcome on GitHub at [https://github.com/YamabikoLab/rails-crud](https://github.com/YamabikoLab/rails-crud).
|
99
|
-
|
100
|
-
When contributing, please:
|
101
|
-
- Fork the repository.
|
102
|
-
- Create a feature branch.
|
103
|
-
- Submit a pull request with a clear description of your changes.
|
104
|
-
|
105
|
-
## License
|
106
|
-
|
107
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
108
|
-
|
data/Rakefile
DELETED
data/docker-compose.yml
DELETED
data/exe/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "bundler/setup"
|
5
|
-
require "rails/crud/tools"
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require "irb"
|
15
|
-
IRB.start(__FILE__)
|
data/exe/crud
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
ENV["SKIP_CRUD_SETUP"] = "true"
|
3
|
-
require "rails/crud/tools/cli"
|
4
|
-
|
5
|
-
def display_help
|
6
|
-
puts <<~HELP
|
7
|
-
Usage: crud [command]
|
8
|
-
|
9
|
-
Commands:
|
10
|
-
init Initialize by generating CRUD and config files
|
11
|
-
gen_crud Generate CRUD
|
12
|
-
gen_config Generate config
|
13
|
-
help Display this help message
|
14
|
-
HELP
|
15
|
-
end
|
16
|
-
|
17
|
-
if ARGV.empty? || ARGV.include?("help")
|
18
|
-
display_help
|
19
|
-
elsif ARGV.include?("init")
|
20
|
-
RailsCrudTools::CLI.init
|
21
|
-
elsif ARGV.include?("gen_crud")
|
22
|
-
RailsCrudTools::CLI.generate_crud_file
|
23
|
-
elsif ARGV.include?("gen_config")
|
24
|
-
RailsCrudTools::CLI.generate_crudconfig
|
25
|
-
else
|
26
|
-
puts "Unknown command: #{ARGV.join(' ')}"
|
27
|
-
display_help
|
28
|
-
end
|
data/exe/setup
DELETED
data/lib/rails/crud/tools/cli.rb
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
require "rubyXL"
|
2
|
-
require 'rubyXL/convenience_methods'
|
3
|
-
require 'active_record'
|
4
|
-
require 'yaml'
|
5
|
-
require 'erb'
|
6
|
-
|
7
|
-
module RailsCrudTools
|
8
|
-
class CLI
|
9
|
-
@application_loaded = false
|
10
|
-
class << self
|
11
|
-
def generate_crud_file
|
12
|
-
load_application unless @application_loaded
|
13
|
-
|
14
|
-
# 1. `bundle exec rails routes --expanded`の結果を取得
|
15
|
-
routes_output = `bundle exec rails routes --expanded`
|
16
|
-
config = Rails::Crud::Tools::CrudConfig.instance
|
17
|
-
font_name = config.font_name
|
18
|
-
|
19
|
-
# 2. 取得した結果を区切り文字で分割
|
20
|
-
routes_lines = routes_output.split("\n").reject(&:empty?)
|
21
|
-
routes_data = []
|
22
|
-
current_route = {}
|
23
|
-
|
24
|
-
routes_lines.each do |line|
|
25
|
-
if line.start_with?("--[ Route")
|
26
|
-
routes_data << current_route unless current_route.empty?
|
27
|
-
current_route = {}
|
28
|
-
else
|
29
|
-
key, value = line.split("|").map(&:strip)
|
30
|
-
current_route[key] = value
|
31
|
-
end
|
32
|
-
end
|
33
|
-
routes_data << current_route unless current_route.empty?
|
34
|
-
|
35
|
-
# 3. 全テーブル名を取得し、アルファベット順にソート
|
36
|
-
table_names = ActiveRecord::Base.connection.tables.sort
|
37
|
-
|
38
|
-
# 4. `rubyXL`を使って`xlsx`ファイルに書き込み
|
39
|
-
workbook = RubyXL::Workbook.new
|
40
|
-
sheet = workbook[0]
|
41
|
-
sheet.sheet_name = config.sheet_name
|
42
|
-
|
43
|
-
# ヘッダー行を追加
|
44
|
-
headers = %w[Prefix Verb URI Controller#Action crud_count] + table_names
|
45
|
-
|
46
|
-
headers.each_with_index do |header, index|
|
47
|
-
cell = sheet.add_cell(0, index, header)
|
48
|
-
cell.change_fill("00FFCC")
|
49
|
-
cell.change_font_name(font_name)
|
50
|
-
cell.change_font_bold(true)
|
51
|
-
apply_borders(cell)
|
52
|
-
end
|
53
|
-
|
54
|
-
start_col = "F"
|
55
|
-
end_col = ("A".."ZZ").to_a[table_names.length + 4] # 'F'から始まる列の範囲を計算
|
56
|
-
|
57
|
-
# データ行を追加
|
58
|
-
routes_data.each_with_index do |route, row_index|
|
59
|
-
headers.each_with_index do |header, col_index|
|
60
|
-
cell = sheet.add_cell(row_index + 1, col_index, route[header])
|
61
|
-
cell.change_font_name(font_name)
|
62
|
-
apply_borders(cell)
|
63
|
-
end
|
64
|
-
|
65
|
-
# 追加: crud_count列に式を設定
|
66
|
-
crud_count_formula = "=SUMPRODUCT(LEN(#{start_col}#{row_index + 2}:#{end_col}#{row_index + 2}))"
|
67
|
-
crud_count_cell = sheet.add_cell(row_index + 1, 4, "", crud_count_formula)
|
68
|
-
crud_count_cell.change_font_name(font_name)
|
69
|
-
apply_borders(crud_count_cell)
|
70
|
-
end
|
71
|
-
|
72
|
-
# app/jobs ディレクトリ内のジョブ名を取得
|
73
|
-
job_files = Dir.glob("app/jobs/**/*.rb")
|
74
|
-
job_classes = job_files.map do |file|
|
75
|
-
File.basename(file, ".rb").camelize
|
76
|
-
end.reject { |job| job == "ApplicationJob" }.sort
|
77
|
-
|
78
|
-
# ジョブ名を Controller#Action 列に追加
|
79
|
-
job_classes.each_with_index do |job, index|
|
80
|
-
headers.each_with_index do |header, col_index|
|
81
|
-
if header == "Controller#Action"
|
82
|
-
cell = sheet.add_cell(routes_data.length + 1 + index, col_index, job)
|
83
|
-
cell.change_font_name(font_name)
|
84
|
-
else
|
85
|
-
cell = sheet.add_cell(routes_data.length + 1 + index, col_index, nil)
|
86
|
-
end
|
87
|
-
apply_borders(cell)
|
88
|
-
end
|
89
|
-
|
90
|
-
# 追加: crud_count列に式を設定
|
91
|
-
crud_count_formula = "=SUMPRODUCT(LEN(#{start_col}#{routes_data.length + 2 + index}:#{end_col}#{routes_data.length + 2 + index}))"
|
92
|
-
crud_count_cell = sheet.add_cell(routes_data.length + 1 + index, 4, "", crud_count_formula)
|
93
|
-
crud_count_cell.change_font_name(font_name)
|
94
|
-
apply_borders(crud_count_cell)
|
95
|
-
end
|
96
|
-
|
97
|
-
# ヘッダーの背景色を設定
|
98
|
-
(0..headers.length - 1).each do |col_index|
|
99
|
-
sheet[0][col_index].change_fill(config.header_bg_color)
|
100
|
-
end
|
101
|
-
|
102
|
-
# 列幅を設定
|
103
|
-
headers.each_with_index do |header, col_index|
|
104
|
-
max_length = header.length
|
105
|
-
(1..routes_data.length).each do |row_index|
|
106
|
-
cell_value = sheet[row_index][col_index].value.to_s
|
107
|
-
max_length = [max_length, cell_value.length].max
|
108
|
-
end
|
109
|
-
sheet.change_column_width(col_index, max_length + 2)
|
110
|
-
end
|
111
|
-
|
112
|
-
# ファイルを保存
|
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)
|
118
|
-
workbook.write(crud_file)
|
119
|
-
|
120
|
-
puts "Output: #{crud_file}"
|
121
|
-
end
|
122
|
-
|
123
|
-
def generate_crudconfig
|
124
|
-
load_application unless @application_loaded
|
125
|
-
|
126
|
-
table_names = ActiveRecord::Base.connection.tables.sort
|
127
|
-
table_start_col = table_names.any? ? table_names.first : "active_admin_comments"
|
128
|
-
|
129
|
-
config_content = <<~CONFIG
|
130
|
-
enabled: true
|
131
|
-
base_dir: doc
|
132
|
-
crud_file: crud.xlsx
|
133
|
-
sheet_name: CRUD
|
134
|
-
method_col: Verb
|
135
|
-
action_col: Controller#Action
|
136
|
-
table_start_col: #{table_start_col}
|
137
|
-
sql_logging_enabled: true
|
138
|
-
header_bg_color: 00FFCC
|
139
|
-
font_name: Arial
|
140
|
-
CONFIG
|
141
|
-
|
142
|
-
File.write('.crudconfig', config_content)
|
143
|
-
puts "Generated .crudconfig file"
|
144
|
-
end
|
145
|
-
|
146
|
-
def init
|
147
|
-
generate_crudconfig
|
148
|
-
generate_crud_file
|
149
|
-
end
|
150
|
-
|
151
|
-
private
|
152
|
-
|
153
|
-
def load_application
|
154
|
-
return if @application_loaded
|
155
|
-
|
156
|
-
path = Dir.pwd
|
157
|
-
$stderr.puts "Loading application in '#{File.basename(path)}'..."
|
158
|
-
environment_path = "#{path}/config/environment.rb"
|
159
|
-
require environment_path
|
160
|
-
|
161
|
-
if defined? Rails
|
162
|
-
Rails.application.eager_load!
|
163
|
-
Rails.application.config.eager_load_namespaces.each(&:eager_load!) if Rails.application.config.respond_to?(:eager_load_namespaces)
|
164
|
-
end
|
165
|
-
|
166
|
-
@application_loaded = true
|
167
|
-
rescue ::LoadError
|
168
|
-
error_message = <<~EOS
|
169
|
-
Tried to load your application environment from '#{environment_path}'.
|
170
|
-
EOS
|
171
|
-
puts error_message
|
172
|
-
rescue TypeError
|
173
|
-
end
|
174
|
-
|
175
|
-
def apply_borders(cell)
|
176
|
-
%i[top bottom left right].each do |side|
|
177
|
-
cell.change_border(side, "thin")
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module Crud
|
5
|
-
module Tools
|
6
|
-
class CrudConfig
|
7
|
-
include Singleton
|
8
|
-
|
9
|
-
attr_accessor :enabled, :base_dir, :crud_file, :sheet_name, :method_col, :action_col, :table_start_col, :sql_logging_enabled, :header_bg_color, :font_name
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@config_file = ".crudconfig"
|
13
|
-
@last_loaded = nil
|
14
|
-
load_config
|
15
|
-
end
|
16
|
-
|
17
|
-
def load_config
|
18
|
-
if @last_loaded.nil? || File.mtime(@config_file) > @last_loaded
|
19
|
-
unless File.exist?(@config_file)
|
20
|
-
raise "Config file not found: #{@config_file}. Please generate it using `bundle exec crud gen_config`."
|
21
|
-
end
|
22
|
-
|
23
|
-
config = YAML.load_file(@config_file)
|
24
|
-
|
25
|
-
@enabled = config["enabled"]
|
26
|
-
@base_dir = config["base_dir"]
|
27
|
-
@crud_file = config["crud_file"]
|
28
|
-
@sheet_name = config["sheet_name"]
|
29
|
-
@method_col = config["method_col"]
|
30
|
-
@action_col = config["action_col"]
|
31
|
-
@table_start_col = config["table_start_col"]
|
32
|
-
@sql_logging_enabled = config["sql_logging_enabled"]
|
33
|
-
@header_bg_color = config["header_bg_color"]
|
34
|
-
@font_name = config["font_name"]
|
35
|
-
|
36
|
-
@last_loaded = File.mtime(@config_file)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def crud_file_path
|
41
|
-
File.join(@base_dir, @crud_file)
|
42
|
-
end
|
43
|
-
|
44
|
-
def crud_log_path
|
45
|
-
File.join(@base_dir, @crud_log)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require "zip"
|
2
|
-
require_relative "crud_logger"
|
3
|
-
require_relative "constants"
|
4
|
-
|
5
|
-
module Rails
|
6
|
-
module Crud
|
7
|
-
module Tools
|
8
|
-
# このクラスは、CRUDファイルからデータを読み込むためのクラスです。
|
9
|
-
class CrudData
|
10
|
-
include Singleton
|
11
|
-
|
12
|
-
attr_accessor :process_id, :crud_rows, :crud_cols, :workbook, :last_loaded_time
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@process_id = nil
|
16
|
-
@crud_rows = {}
|
17
|
-
@crud_cols = {}
|
18
|
-
@last_loaded_time = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def load_crud_data
|
22
|
-
config = CrudConfig.instance
|
23
|
-
return unless config.enabled
|
24
|
-
|
25
|
-
unless File.exist?(config.crud_file_path)
|
26
|
-
CrudLogger.logger.warn "CRUD file not found: #{config.crud_file_path}"
|
27
|
-
return false
|
28
|
-
end
|
29
|
-
|
30
|
-
@workbook = RubyXL::Parser.parse(config.crud_file_path)
|
31
|
-
@last_loaded_time = File.mtime(config.crud_file_path)
|
32
|
-
sheet = get_crud_sheet
|
33
|
-
headers = sheet[0].cells.map(&:value)
|
34
|
-
|
35
|
-
method_col_index = headers.index(config.method_col)
|
36
|
-
action_col_index = headers.index(config.action_col)
|
37
|
-
table_start_col_index = headers.index(config.table_start_col)
|
38
|
-
|
39
|
-
raise "Method column not found" unless method_col_index
|
40
|
-
raise "Action column not found" unless action_col_index
|
41
|
-
raise "Table start column not found" unless table_start_col_index
|
42
|
-
|
43
|
-
headers[table_start_col_index..].each_with_index do |table_name, index|
|
44
|
-
@crud_cols[table_name] = table_start_col_index + index
|
45
|
-
end
|
46
|
-
|
47
|
-
sheet.each_with_index do |row, index|
|
48
|
-
next if index.zero?
|
49
|
-
|
50
|
-
method = row[method_col_index]&.value.to_s.strip
|
51
|
-
method = Constants::DEFAULT_METHOD if method.empty?
|
52
|
-
action = row[action_col_index]&.value&.split&.first
|
53
|
-
next if action.nil?
|
54
|
-
|
55
|
-
@crud_rows[method] ||= {}
|
56
|
-
@crud_rows[method][action] = index
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# CRUDデータが更新された場合に再読み込みする
|
61
|
-
def reload_if_needed
|
62
|
-
config = CrudConfig.instance
|
63
|
-
return unless config.enabled
|
64
|
-
|
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
|
-
|
71
|
-
CrudLogger.logger.info "Reloading CRUD data due to file modification. last_loaded_time = #{@last_loaded_time}"
|
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
|
88
|
-
|
89
|
-
last_modified_by
|
90
|
-
end
|
91
|
-
|
92
|
-
# CRUDシートを取得する
|
93
|
-
def get_crud_sheet
|
94
|
-
sheet_name = CrudConfig.instance.sheet_name
|
95
|
-
sheet = @workbook[sheet_name]
|
96
|
-
raise "CRUD sheet '#{sheet_name}' not found" if sheet.nil?
|
97
|
-
|
98
|
-
sheet
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'singleton'
|
3
|
-
|
4
|
-
module Rails
|
5
|
-
module Crud
|
6
|
-
module Tools
|
7
|
-
class CrudLogger
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@logger = Logger.new("log/crud.log")
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.logger
|
15
|
-
instance.logger
|
16
|
-
end
|
17
|
-
|
18
|
-
def logger
|
19
|
-
@logger
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,156 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_support/notifications"
|
4
|
-
|
5
|
-
# Notification を使用して SQL クエリを監視するためのモジュール
|
6
|
-
module Rails
|
7
|
-
module Crud
|
8
|
-
module Tools
|
9
|
-
def self.setup_notifications
|
10
|
-
# 初回呼び出し時に @subscribed を false に設定
|
11
|
-
@subscribed ||= false
|
12
|
-
# 既に通知が登録されている場合は処理を中断
|
13
|
-
return if @subscribed
|
14
|
-
|
15
|
-
if CrudConfig.instance.enabled
|
16
|
-
# SQL クエリを監視する
|
17
|
-
ActiveSupport::Notifications.subscribe(/sql.active_record/) do |_name, _started, _finished, _unique_id, data|
|
18
|
-
process_sql(data)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# 通知の登録が完了した後に @subscribed を true に設定
|
23
|
-
@subscribed = true
|
24
|
-
end
|
25
|
-
|
26
|
-
OPERATION_UNKNOWN = "Unknown"
|
27
|
-
|
28
|
-
def self.process_sql(data)
|
29
|
-
return unless data[:sql] =~ /\A\s*(INSERT|UPDATE|DELETE|SELECT)/i
|
30
|
-
|
31
|
-
case data[:sql]
|
32
|
-
when /\bINSERT INTO\b.*\bSELECT\b/i
|
33
|
-
handle_insert_select(data)
|
34
|
-
when /\bUPDATE\b.*\bSET\b.*\bSELECT\b/i
|
35
|
-
handle_update_select(data)
|
36
|
-
when /\bDELETE\b.*\bEXISTS\b.*\bSELECT\b/i
|
37
|
-
handle_delete_select(data)
|
38
|
-
else
|
39
|
-
handle_general_sql(data)
|
40
|
-
end
|
41
|
-
|
42
|
-
return unless CrudConfig.instance.sql_logging_enabled
|
43
|
-
|
44
|
-
# SQL ログを出力
|
45
|
-
CrudLogger.logger.info "#{data[:name]} - #{data[:sql]}"
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.handle_insert_select(data)
|
49
|
-
# INSERT INTO ... SELECT の特別な処理
|
50
|
-
insert_table = data[:sql].match(/INSERT INTO\s+`?(\w+)`?/i)[1]
|
51
|
-
select_tables = data[:sql].scan(/SELECT .* FROM\s+`?(\w+)`?(?:\s*,\s*`?(\w+)`?)*|JOIN\s+`?(\w+)`?/i).flatten.compact.uniq
|
52
|
-
|
53
|
-
key, method = determine_key_and_method
|
54
|
-
if key.nil? || method.nil?
|
55
|
-
CrudLogger.logger.warn "Request not found. #{data[:name]} - #{data[:sql]}"
|
56
|
-
return
|
57
|
-
end
|
58
|
-
|
59
|
-
CrudOperations.instance.add_operation(method, key, insert_table, "C")
|
60
|
-
select_tables.each do |select_table|
|
61
|
-
CrudOperations.instance.add_operation(method, key, select_table, "R")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.handle_update_select(data)
|
66
|
-
# UPDATE ... SET ... SELECT の特別な処理
|
67
|
-
update_table = data[:sql].match(/UPDATE\s+`?(\w+)`?/i)[1]
|
68
|
-
select_tables = data[:sql].scan(/SELECT .* FROM\s+`?(\w+)`?(?:\s*,\s*`?(\w+)`?)*|JOIN\s+`?(\w+)`?/i).flatten.compact.uniq
|
69
|
-
|
70
|
-
key, method = determine_key_and_method
|
71
|
-
if key.nil? || method.nil?
|
72
|
-
CrudLogger.logger.warn "Request not found. #{data[:name]} - #{data[:sql]}"
|
73
|
-
return
|
74
|
-
end
|
75
|
-
|
76
|
-
CrudOperations.instance.add_operation(method, key, update_table, "U")
|
77
|
-
select_tables.each do |select_table|
|
78
|
-
CrudOperations.instance.add_operation(method, key, select_table, "R")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.handle_delete_select(data)
|
83
|
-
# DELETE ... WHERE EXISTS ... SELECT の特別な処理
|
84
|
-
delete_table = data[:sql].match(/DELETE FROM\s+`?(\w+)`?/i)[1]
|
85
|
-
select_tables = data[:sql].scan(/SELECT .* FROM\s+`?(\w+)`?(?:\s*,\s*`?(\w+)`?)*|JOIN\s+`?(\w+)`?/i).flatten.compact.uniq
|
86
|
-
|
87
|
-
key, method = determine_key_and_method
|
88
|
-
if key.nil? || method.nil?
|
89
|
-
CrudLogger.logger.warn "Request not found. #{data[:name]} - #{data[:sql]}"
|
90
|
-
return
|
91
|
-
end
|
92
|
-
|
93
|
-
CrudOperations.instance.add_operation(method, key, delete_table, "D")
|
94
|
-
select_tables.each do |select_table|
|
95
|
-
CrudOperations.instance.add_operation(method, key, select_table, "R")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.handle_general_sql(data)
|
100
|
-
operation = if (match = data[:sql].match(/\A\s*(INSERT|UPDATE|DELETE|SELECT)/i))
|
101
|
-
case match[1].upcase
|
102
|
-
when "INSERT" then "C"
|
103
|
-
when "SELECT" then "R"
|
104
|
-
when "UPDATE" then "U"
|
105
|
-
when "DELETE" then "D"
|
106
|
-
else OPERATION_UNKNOWN
|
107
|
-
end
|
108
|
-
else
|
109
|
-
OPERATION_UNKNOWN
|
110
|
-
end
|
111
|
-
|
112
|
-
if operation == OPERATION_UNKNOWN
|
113
|
-
warn "Warning: Unknown SQL operation. #{data[:name]} - #{data[:sql]}"
|
114
|
-
return
|
115
|
-
end
|
116
|
-
|
117
|
-
table_names = data[:sql].scan(/(?:INSERT INTO|UPDATE|DELETE FROM|FROM|JOIN)\s+`?(\w+)`?(?:\s*,\s*`?(\w+)`?)*/i).flatten.compact.uniq
|
118
|
-
if table_names.empty?
|
119
|
-
# テーブル名が見つからない場合は警告を出力
|
120
|
-
CrudLogger.logger.warn "Table name not found in SQL: #{data[:sql]}"
|
121
|
-
return
|
122
|
-
end
|
123
|
-
|
124
|
-
key, method = determine_key_and_method
|
125
|
-
if key.nil? || method.nil?
|
126
|
-
CrudLogger.logger.warn "Request not found. #{data[:name]} - #{data[:sql]}"
|
127
|
-
return
|
128
|
-
end
|
129
|
-
|
130
|
-
# テーブル名を取得して CRUD 操作に追加
|
131
|
-
table_names.each do |table_name|
|
132
|
-
CrudOperations.instance.add_operation(method, key, table_name, operation)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
# キーとメソッドを決定する
|
136
|
-
def self.determine_key_and_method
|
137
|
-
request = Thread.current[:crud_request]
|
138
|
-
sidekiq_job_class = Thread.current[:crud_sidekiq_job_class]
|
139
|
-
|
140
|
-
if request
|
141
|
-
method = request.request_method
|
142
|
-
controller = request.params["controller"]
|
143
|
-
action = request.params["action"]
|
144
|
-
key = "#{controller}##{action}"
|
145
|
-
elsif sidekiq_job_class
|
146
|
-
key = sidekiq_job_class
|
147
|
-
method = Constants::DEFAULT_METHOD
|
148
|
-
else
|
149
|
-
return nil
|
150
|
-
end
|
151
|
-
|
152
|
-
[key, method]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require_relative 'crud_logger'
|
2
|
-
require_relative 'constants'
|
3
|
-
|
4
|
-
module Rails
|
5
|
-
module Crud
|
6
|
-
module Tools
|
7
|
-
class CrudOperations
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
attr_accessor :table_operations, :logs
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@table_operations = Hash.new do |hash, method|
|
14
|
-
hash[method] = Hash.new do |h, key|
|
15
|
-
h[key] = Hash.new do |hh, table|
|
16
|
-
hh[table] = []
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_operation(method, key, table_name, operation)
|
23
|
-
# @table_operations[method]が存在しない場合は初期化
|
24
|
-
@table_operations[method] ||= {}
|
25
|
-
# @table_operations[method][key]が存在しない場合は初期化
|
26
|
-
@table_operations[method][key] ||= {}
|
27
|
-
# @table_operations[method][key][table_name]が存在しない場合は初期化
|
28
|
-
@table_operations[method][key][table_name] ||= []
|
29
|
-
|
30
|
-
@table_operations[method][key][table_name] << operation unless @table_operations[method][key][table_name].include?(operation)
|
31
|
-
end
|
32
|
-
|
33
|
-
def log_operations(method, key)
|
34
|
-
CrudLogger.logger.info "\nSummary: Method: #{method}, Key: #{key}"
|
35
|
-
|
36
|
-
@table_operations[method][key].each do |table_name, operations|
|
37
|
-
CrudLogger.logger.info "#{table_name} - #{operations.join(', ')}"
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def table_operations_present?(method, key)
|
43
|
-
return false if @table_operations[method].nil?
|
44
|
-
return false if @table_operations[method][key].nil?
|
45
|
-
!@table_operations[method][key].empty?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,167 +0,0 @@
|
|
1
|
-
require "zip"
|
2
|
-
require_relative "crud_logger"
|
3
|
-
require_relative "constants"
|
4
|
-
|
5
|
-
# ログ出力を行うモジュール
|
6
|
-
module Rails
|
7
|
-
module Crud
|
8
|
-
module Tools
|
9
|
-
module OperationsLogger
|
10
|
-
|
11
|
-
# コントローラのCRUD操作をログ出力する
|
12
|
-
def log_crud_operations
|
13
|
-
if CrudConfig.instance.enabled
|
14
|
-
CrudConfig.instance.load_config
|
15
|
-
log_request_details
|
16
|
-
Thread.current[:crud_request] = request
|
17
|
-
end
|
18
|
-
|
19
|
-
yield
|
20
|
-
|
21
|
-
if CrudConfig.instance.enabled
|
22
|
-
key = "#{controller_path}##{action_name}"
|
23
|
-
method = request.request_method
|
24
|
-
if CrudOperations.instance.table_operations_present?(method, key)
|
25
|
-
CrudOperations.instance.log_operations(method, key)
|
26
|
-
log_and_write_operations(method, key)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
ensure
|
30
|
-
Thread.current[:crud_request] = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
# ジョブのCRUD操作をログ出力する
|
34
|
-
def log_crud_operations_for_job
|
35
|
-
if CrudConfig.instance.enabled
|
36
|
-
CrudConfig.instance.load_config
|
37
|
-
log_job_details
|
38
|
-
key = self.class.name
|
39
|
-
Thread.current[:crud_sidekiq_job_class] = key
|
40
|
-
end
|
41
|
-
|
42
|
-
yield
|
43
|
-
|
44
|
-
if CrudConfig.instance.enabled
|
45
|
-
if CrudOperations.instance.table_operations_present?(Constants::DEFAULT_METHOD, key)
|
46
|
-
CrudOperations.instance.log_operations(Constants::DEFAULT_METHOD, key)
|
47
|
-
log_and_write_operations(Constants::DEFAULT_METHOD, key)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
ensure
|
51
|
-
Thread.current[:crud_sidekiq_job_class] = nil
|
52
|
-
end
|
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
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
# リクエストの詳細をログ出力する
|
82
|
-
def log_request_details
|
83
|
-
method = request.request_method
|
84
|
-
CrudLogger.logger.info "******************** Method: #{method}, Controller: #{controller_path}, Action: #{action_name}, Key: #{controller_path}##{action_name} ********************"
|
85
|
-
end
|
86
|
-
|
87
|
-
# ジョブの詳細をログ出力する
|
88
|
-
def log_job_details
|
89
|
-
job_name = self.class.name
|
90
|
-
CrudLogger.logger.info "******************** Job: #{job_name} ********************"
|
91
|
-
end
|
92
|
-
|
93
|
-
# ExcelファイルにCRUD操作を書き込む
|
94
|
-
def log_and_write_operations(method, key)
|
95
|
-
CrudData.instance.reload_if_needed
|
96
|
-
sheet = CrudData.instance.get_crud_sheet
|
97
|
-
|
98
|
-
# フラグを初期化
|
99
|
-
contents_changed = false
|
100
|
-
|
101
|
-
CrudOperations.instance.table_operations[method][key].each_key do |table_name|
|
102
|
-
row = CrudData.instance.crud_rows[method][key]
|
103
|
-
col = CrudData.instance.crud_cols[table_name]
|
104
|
-
|
105
|
-
# colまたはrowが存在しない場合にログ出力してスキップ
|
106
|
-
unless row && col
|
107
|
-
CrudLogger.logger.warn "Row or Column not found for table: #{table_name}, method: #{method}, key: #{key}, row: #{row}, col: #{col}"
|
108
|
-
next
|
109
|
-
end
|
110
|
-
|
111
|
-
# sheet[row][col]がnilの場合に警告文を出力し、空文字列として処理を進める
|
112
|
-
cell = sheet[row][col]
|
113
|
-
if cell.nil?
|
114
|
-
cell = sheet.add_cell(row, col, "")
|
115
|
-
CrudLogger.logger.warn "Cell not found at row: #{row}, col: #{col} for table: #{table_name}, method: #{method}, key: #{key}. Adding new cell."
|
116
|
-
existing_value = ""
|
117
|
-
else
|
118
|
-
existing_value = cell.value || ""
|
119
|
-
end
|
120
|
-
|
121
|
-
# 新しい値と既存の値を結合し、重複を排除
|
122
|
-
new_value = CrudOperations.instance.table_operations[method][key][table_name].join
|
123
|
-
merged_value = (existing_value.chars + new_value.chars).uniq
|
124
|
-
|
125
|
-
# CRUDの順序に並び替え
|
126
|
-
crud_order = %w[C R U D]
|
127
|
-
sorted_value = merged_value.sort_by { |char| crud_order.index(char) }.join
|
128
|
-
|
129
|
-
# 値が変化した場合のみ change_contents を実行
|
130
|
-
if cell.value != sorted_value
|
131
|
-
cell.change_contents(sorted_value)
|
132
|
-
contents_changed = true
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
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
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rails/railtie'
|
2
|
-
require_relative 'crud_operations_logger'
|
3
|
-
|
4
|
-
module Rails
|
5
|
-
module Crud
|
6
|
-
module Tools
|
7
|
-
class Railtie < ::Rails::Railtie
|
8
|
-
initializer 'rails-crud.add_after_action' do
|
9
|
-
ActiveSupport.on_load(:action_controller) do
|
10
|
-
include Rails::Crud::Tools::OperationsLogger
|
11
|
-
|
12
|
-
# 全てのコントローラにafter_actionフィルタを追加
|
13
|
-
ActionController::Base.class_eval do
|
14
|
-
around_action :log_crud_operations
|
15
|
-
end
|
16
|
-
|
17
|
-
# APIモードの場合はActionController::APIにも追加
|
18
|
-
ActionController::API.class_eval do
|
19
|
-
around_action :log_crud_operations
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# ActiveJobにもフィルタを追加
|
24
|
-
ActiveSupport.on_load(:active_job) do
|
25
|
-
include Rails::Crud::Tools::OperationsLogger
|
26
|
-
|
27
|
-
# 全てのジョブにaround_performフィルタを追加
|
28
|
-
ActiveJob::Base.class_eval do
|
29
|
-
around_perform :log_crud_operations_for_job
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/rails/crud/tools.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require "rubyXL"
|
2
|
-
require "rubyXL/convenience_methods/cell"
|
3
|
-
require "rubyXL/convenience_methods/color"
|
4
|
-
require "rubyXL/convenience_methods/font"
|
5
|
-
require "rubyXL/convenience_methods/workbook"
|
6
|
-
require "rubyXL/convenience_methods/worksheet"
|
7
|
-
require_relative "tools/crud_operations"
|
8
|
-
require_relative "tools/crud_config"
|
9
|
-
require_relative "tools/crud_notifications"
|
10
|
-
require_relative "tools/railtie"
|
11
|
-
require_relative "tools/crud_data"
|
12
|
-
|
13
|
-
module Rails
|
14
|
-
module Crud
|
15
|
-
module Tools
|
16
|
-
def self.setup()
|
17
|
-
unless File.exist?(".crudconfig")
|
18
|
-
puts "The .crudconfig file is required. Please run `bundle exec crud init`."
|
19
|
-
return
|
20
|
-
end
|
21
|
-
|
22
|
-
unless File.exist?(CrudConfig.instance.crud_file_path)
|
23
|
-
puts "The CRUD file is required. Please run `bundle exec crud gen_crud`."
|
24
|
-
return
|
25
|
-
end
|
26
|
-
|
27
|
-
CrudData.instance.process_id = "rails-crud-tools-#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
28
|
-
CrudData.instance.load_crud_data
|
29
|
-
setup_notifications
|
30
|
-
end
|
31
|
-
|
32
|
-
setup unless ENV["SKIP_CRUD_SETUP"] == "true"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/sig/rails/crud.rbs
DELETED
data/tools/crud_macro.xlsm
DELETED
Binary file
|