rails-crud-tools 0.6.9 → 0.6.10

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: 9d60769342a2c4f14ca5185dac7446f06fb2ab137c2835f004da3994a97bad2d
4
- data.tar.gz: d0f0ba569e37b04b0d5e5692b4ca60c05becc2ab3c91b0da2a315e12ca26f274
3
+ metadata.gz: f093aa23597638ca343e4b2f5e19ccf2e49399728da2e96eb6dc1103d1281e45
4
+ data.tar.gz: fc4d4f153eeb5d192822fd359d3d0b104d19689bf2bb59d078955bd4f36c2ad7
5
5
  SHA512:
6
- metadata.gz: 3cfd62496d6616601689aa943fd6a4face9369249489dbb88d1be2c825b69118e28ac850cd9e91299930153a91b38ff7d9caa1413d1d5592d58ec58a9c8ce141
7
- data.tar.gz: fcc34ae205587a64a795e07ad9d5111443a86d4913cfda3823a72358c53c0c0cca7290726b652b2a349990afb5c322402711d99ffaa544795252a448401db4e7
6
+ metadata.gz: 73d9ba0b4425afc54440ce49a6383e42cfee4888c0c4fcdc25a4e9f696468a56462cc782abaabf02f40268e14cd555948750921a185c1180a44132e7a2fa7c3c
7
+ data.tar.gz: 63e0033da0b7c56e64f75913f8978bdb7b4496363438efcee6d772db866bd45dbd34698ba47c4b980b0066495f6695c2b0035db6526b6892cc39965d423046f3
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.7
2
+ TargetRubyVersion: 3.1
3
3
  Exclude:
4
4
  - 'ide/**/*'
5
5
  - 'spec/**/*'
data/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
- ## [0.6.3] - 2025-01-09
2
- - refactoring gem dependency
1
+ ## [0.6.10] - 2025-01-11
2
+ - Required ruby version up
3
+ - Change configuration file to yaml format
3
4
 
4
- ## [0.6.2] - 2025-01-09
5
- - bug fix:uninitialized constant RubyXL::Cell
5
+ ## [0.6.9] - 2025-01-10
6
+ - refactoring gem dependency
6
7
 
7
8
  ## [0.6.1] - 2025-01-09
8
9
  - Rubocop support
data/README.md CHANGED
@@ -37,14 +37,15 @@ $ bundle exec crud init
37
37
  ```yaml
38
38
  enabled: true # Enables or disables the CRUD tools functionality
39
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
40
+ crud_file:
41
+ file_name: crud.xlsx # The name of the CRUD Excel file
42
+ sheet_name: CRUD # The name of the sheet in the CRUD Excel file
43
+ header_bg_color: 00FFCC # The background color for the header in the CRUD Excel file
44
+ font_name: Arial # The font name used in the CRUD Excel file
42
45
  method_col: Verb # Column indicating the HTTP method
43
46
  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
47
+ table_start_col: your_first_table # Column where the table starts
46
48
  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
  ```
49
50
 
50
51
  ### How It Works
data/docker-compose.yml CHANGED
@@ -5,7 +5,7 @@ services:
5
5
  container_name: rails-crud-tools
6
6
  volumes:
7
7
  - .:/root/app
8
- - ./ide:/root/app/ide
8
+ - /root/app/ide
9
9
  ports:
10
10
  - '5995:5995'
11
11
  tty: true
@@ -11,14 +11,15 @@ module RailsCrudTools
11
11
  # It includes methods to generate CRUD files, generate configuration files, and initialize the application.
12
12
  class CLI
13
13
  @application_loaded = false
14
+
14
15
  class << self
15
16
  def generate_crud_file
16
17
  load_application unless @application_loaded
17
18
 
18
19
  # 1. `bundle exec rails routes --expanded`の結果を取得
19
20
  routes_output = `bundle exec rails routes --expanded`
20
- config = Rails::Crud::Tools::CrudConfig.instance
21
- font_name = config.font_name
21
+ config = Rails::Crud::Tools::CrudConfig.instance.config
22
+ font_name = config.crud_file.font_name
22
23
 
23
24
  # 2. 取得した結果を区切り文字で分割
24
25
  routes_lines = routes_output.split("\n").reject(&:empty?)
@@ -42,7 +43,7 @@ module RailsCrudTools
42
43
  # 4. `rubyXL`を使って`xlsx`ファイルに書き込み
43
44
  workbook = RubyXL::Workbook.new
44
45
  sheet = workbook[0]
45
- sheet.sheet_name = config.sheet_name
46
+ sheet.sheet_name = config.crud_file.sheet_name
46
47
 
47
48
  # ヘッダー行を追加
48
49
  headers = %w[Prefix Verb URI Controller#Action crud_count] + table_names
@@ -100,7 +101,7 @@ module RailsCrudTools
100
101
 
101
102
  # ヘッダーの背景色を設定
102
103
  (0..headers.length - 1).each do |col_index|
103
- sheet[0][col_index].change_fill(config.header_bg_color)
104
+ sheet[0][col_index].change_fill(config.crud_file.header_bg_color)
104
105
  end
105
106
 
106
107
  # 列幅を設定
@@ -133,14 +134,15 @@ module RailsCrudTools
133
134
  config_content = <<~CONFIG
134
135
  enabled: true
135
136
  base_dir: doc
136
- crud_file: crud.xlsx
137
- sheet_name: CRUD
137
+ crud_file:
138
+ file_name: crud.xlsx
139
+ sheet_name: CRUD
140
+ header_bg_color: 00FFCC
141
+ font_name: Arial
138
142
  method_col: Verb
139
143
  action_col: Controller#Action
140
144
  table_start_col: #{table_start_col}
141
145
  sql_logging_enabled: true
142
- header_bg_color: 00FFCC
143
- font_name: Arial
144
146
  CONFIG
145
147
 
146
148
  File.write(".crudconfig.yml", config_content)
@@ -1,49 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "yaml"
4
+ require "singleton"
4
5
 
5
6
  module Rails
6
7
  module Crud
7
8
  module Tools
8
- # The CrudConfig class is responsible for loading and managing the configuration settings for CRUD operations.
9
- # It uses the Singleton pattern to ensure only one instance of the configuration exists.
9
+ # The CrudConfig class is a singleton class responsible for loading and managing configuration settings from a YAML file (.crudconfig.yml).
10
+ # It ensures that the configuration is reloaded if the file is updated.
10
11
  class CrudConfig
11
12
  include Singleton
12
13
 
13
- attr_reader :enabled, :base_dir, :crud_file, :sheet_name, :method_col, :action_col, :table_start_col, :sql_logging_enabled, :header_bg_color, :font_name, :config_file
14
+ CONFIG_PATH = File.expand_path(".crudconfig.yml", Dir.pwd)
14
15
 
15
16
  def initialize
16
- @config_file = ".crudconfig.yml"
17
- @last_loaded = nil
18
- load_config
17
+ @last_loaded_time = Time.at(0)
18
+ end
19
+
20
+ def self.config_path
21
+ CONFIG_PATH
22
+ end
23
+
24
+ def config
25
+ load_config if @config.nil? || config_file_updated?
26
+ @config
19
27
  end
20
28
 
21
29
  def load_config
22
- return unless @last_loaded.nil? || File.mtime(@config_file) > @last_loaded
23
- raise "Config file not found: #{@config_file}. Please generate it using `bundle exec crud gen_config`." unless File.exist?(@config_file)
24
-
25
- config = YAML.load_file(@config_file)
26
-
27
- @enabled = config["enabled"]
28
- @base_dir = config["base_dir"]
29
- @crud_file = config["crud_file"]
30
- @sheet_name = config["sheet_name"]
31
- @method_col = config["method_col"]
32
- @action_col = config["action_col"]
33
- @table_start_col = config["table_start_col"]
34
- @sql_logging_enabled = config["sql_logging_enabled"]
35
- @header_bg_color = config["header_bg_color"]
36
- @font_name = config["font_name"]
37
-
38
- @last_loaded = File.mtime(@config_file)
30
+ @config = deep_convert_to_struct(YAML.load_file(CONFIG_PATH))
31
+ @last_loaded_time = File.mtime(CONFIG_PATH)
32
+ rescue Errno::ENOENT
33
+ raise "Configuration file not found: #{CONFIG_PATH}"
34
+ rescue Psych::SyntaxError => e
35
+ raise "YAML syntax error occurred while parsing #{CONFIG_PATH}: #{e.message}"
39
36
  end
40
37
 
41
- def crud_file_path
42
- File.join(@base_dir, @crud_file)
38
+ private
39
+
40
+ def config_file_updated?
41
+ File.mtime(CONFIG_PATH) > @last_loaded_time
43
42
  end
44
43
 
45
- def crud_log_path
46
- File.join(@base_dir, @crud_log)
44
+ # Recursively convert hash to Struct and add crud_file_path method
45
+ def deep_convert_to_struct(hash)
46
+ struct_class = Struct.new(*hash.keys.map(&:to_sym)) do
47
+ def crud_file_path
48
+ File.join(base_dir, crud_file.file_name)
49
+ end
50
+ end
51
+ struct_class.new(*hash.values.map { |value| value.is_a?(Hash) ? deep_convert_to_struct(value) : value })
47
52
  end
48
53
  end
49
54
  end
@@ -22,7 +22,7 @@ module Rails
22
22
  end
23
23
 
24
24
  def load_crud_data
25
- config = CrudConfig.instance
25
+ config = CrudConfig.instance.config
26
26
  return unless config.enabled
27
27
 
28
28
  unless File.exist?(config.crud_file_path)
@@ -64,7 +64,7 @@ module Rails
64
64
 
65
65
  # CRUDデータが更新された場合に再読み込みする
66
66
  def reload_if_needed
67
- config = CrudConfig.instance
67
+ config = CrudConfig.instance.config
68
68
  return unless config.enabled
69
69
 
70
70
  return unless @last_loaded_time.nil? || File.mtime(config.crud_file_path) > @last_loaded_time
@@ -85,7 +85,7 @@ module Rails
85
85
  doc_props = zipfile.find_entry("docProps/core.xml")
86
86
  if doc_props
87
87
  content = doc_props.get_input_stream.read
88
- last_modified_by = content[%r{<cp:lastModifiedBy>(.*?)<\\\\/cp:lastModifiedBy>}, 1]
88
+ last_modified_by = content[%r{<cp:lastModifiedBy>(.*?)</cp:lastModifiedBy>}, 1]
89
89
  else
90
90
  CrudLogger.logger.warn "docProps/core.xml が見つかりませんでした。"
91
91
  end
@@ -96,7 +96,7 @@ module Rails
96
96
 
97
97
  # CRUDシートを取得する
98
98
  def crud_sheet
99
- sheet_name = CrudConfig.instance.sheet_name
99
+ sheet_name = CrudConfig.instance.config.crud_file.sheet_name
100
100
  sheet = @workbook[sheet_name]
101
101
  raise "CRUD sheet '#{sheet_name}' not found" if sheet.nil?
102
102
 
@@ -13,7 +13,7 @@ module Rails
13
13
  # 既に通知が登録されている場合は処理を中断
14
14
  return if @subscribed
15
15
 
16
- if CrudConfig.instance.enabled
16
+ if CrudConfig.instance.config.enabled
17
17
  # SQL クエリを監視する
18
18
  ActiveSupport::Notifications.subscribe(/sql.active_record/) do |_name, _started, _finished, _unique_id, data|
19
19
  process_sql(data)
@@ -40,7 +40,7 @@ module Rails
40
40
  handle_general_sql(data)
41
41
  end
42
42
 
43
- return unless CrudConfig.instance.sql_logging_enabled
43
+ return unless CrudConfig.instance.config.sql_logging_enabled
44
44
 
45
45
  # SQL ログを出力
46
46
  CrudLogger.logger.info "#{data[:name]} - #{data[:sql]}"
@@ -12,7 +12,8 @@ module Rails
12
12
  module OperationsLogger
13
13
  # コントローラのCRUD操作をログ出力する
14
14
  def log_crud_operations
15
- if CrudConfig.instance.enabled
15
+ config = CrudConfig.instance.config
16
+ if config.enabled
16
17
  CrudConfig.instance.load_config
17
18
  log_request_details
18
19
  Thread.current[:crud_request] = request
@@ -20,7 +21,7 @@ module Rails
20
21
 
21
22
  yield
22
23
 
23
- if CrudConfig.instance.enabled
24
+ if config.enabled
24
25
  key = "#{controller_path}##{action_name}"
25
26
  method = request.request_method
26
27
  if CrudOperations.instance.table_operations_present?(method, key)
@@ -34,7 +35,8 @@ module Rails
34
35
 
35
36
  # ジョブのCRUD操作をログ出力する
36
37
  def log_crud_operations_for_job
37
- if CrudConfig.instance.enabled
38
+ config = CrudConfig.instance.config
39
+ if config.enabled
38
40
  CrudConfig.instance.load_config
39
41
  log_job_details
40
42
  key = self.class.name
@@ -43,7 +45,7 @@ module Rails
43
45
 
44
46
  yield
45
47
 
46
- if CrudConfig.instance.enabled && CrudOperations.instance.table_operations_present?(Constants::DEFAULT_METHOD, key)
48
+ if config.enabled && CrudOperations.instance.table_operations_present?(Constants::DEFAULT_METHOD, key)
47
49
  CrudOperations.instance.log_operations(Constants::DEFAULT_METHOD, key)
48
50
  log_and_write_operations(Constants::DEFAULT_METHOD, key)
49
51
  end
@@ -138,12 +140,12 @@ module Rails
138
140
  Thread.new do
139
141
  update_crud_file
140
142
  rescue StandardError => e
141
- CrudLogger.logger.error "Failed to update #{CrudConfig.instance.crud_file_path}: #{e.message}"
143
+ CrudLogger.logger.error "Failed to update #{CrudConfig.instance.config.crud_file_path}: #{e.message}"
142
144
  end
143
145
  end
144
146
 
145
147
  def update_crud_file
146
- File.open(CrudConfig.instance.crud_file_path, "r+") do |crud_file|
148
+ File.open(CrudConfig.instance.config.crud_file_path, "r+") do |crud_file|
147
149
  crud_file.flock(File::LOCK_EX)
148
150
  begin
149
151
  # Excelファイルを書き込む
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Crud
5
5
  module Tools
6
- VERSION = "0.6.9"
6
+ VERSION = "0.6.10"
7
7
  end
8
8
  end
9
9
  end
@@ -18,12 +18,12 @@ module Rails
18
18
  # It includes methods to subscribe to ActiveSupport notifications and handle different types of SQL operations.
19
19
  module Tools
20
20
  def self.setup
21
- unless File.exist?(CrudConfig.instance.config_file)
21
+ unless File.exist?(CrudConfig.config_path)
22
22
  puts "The .crudconfig.yml file is required. Please run `bundle exec crud init`."
23
23
  return
24
24
  end
25
25
 
26
- unless File.exist?(CrudConfig.instance.crud_file_path)
26
+ unless File.exist?(CrudConfig.instance.config.crud_file_path)
27
27
  puts "The CRUD file is required. Please run `bundle exec crud gen crud`."
28
28
  return
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-crud-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - yhijikata
@@ -104,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - ">="
106
106
  - !ruby/object:Gem::Version
107
- version: 2.7.0
107
+ version: '3.1'
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ">="