Class: Rails::Crud::Tools::CrudOperations
- Inherits:
-
Object
- Object
- Rails::Crud::Tools::CrudOperations
- Includes:
- Singleton
- Defined in:
- lib/rails/crud/tools/crud_operations.rb
Overview
The CrudOperations class is responsible for managing CRUD operations for different tables. It stores operations in a nested hash structure and provides methods to add and log operations.
Instance Attribute Summary collapse
-
#logs ⇒ Object
Returns the value of attribute logs.
-
#table_operations ⇒ Object
Returns the value of attribute table_operations.
Instance Method Summary collapse
- #add_operation(method, key, table_name, operation) ⇒ Object
-
#initialize ⇒ CrudOperations
constructor
A new instance of CrudOperations.
- #log_operations(method, key) ⇒ Object
- #table_operations_present?(method, key) ⇒ Boolean
Constructor Details
#initialize ⇒ CrudOperations
Returns a new instance of CrudOperations.
16 17 18 19 20 21 22 23 24 |
# File 'lib/rails/crud/tools/crud_operations.rb', line 16 def initialize @table_operations = Hash.new do |hash, method| hash[method] = Hash.new do |h, key| h[key] = Hash.new do |hh, table| hh[table] = [] end end end end |
Instance Attribute Details
#logs ⇒ Object
Returns the value of attribute logs.
14 15 16 |
# File 'lib/rails/crud/tools/crud_operations.rb', line 14 def logs @logs end |
#table_operations ⇒ Object
Returns the value of attribute table_operations.
14 15 16 |
# File 'lib/rails/crud/tools/crud_operations.rb', line 14 def table_operations @table_operations end |
Instance Method Details
#add_operation(method, key, table_name, operation) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails/crud/tools/crud_operations.rb', line 26 def add_operation(method, key, table_name, operation) # @table_operations[method]が存在しない場合は初期化 @table_operations[method] ||= {} # @table_operations[method][key]が存在しない場合は初期化 @table_operations[method][key] ||= {} # @table_operations[method][key][table_name]が存在しない場合は初期化 @table_operations[method][key][table_name] ||= [] @table_operations[method][key][table_name] << operation unless @table_operations[method][key][table_name].include?(operation) end |
#log_operations(method, key) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rails/crud/tools/crud_operations.rb', line 37 def log_operations(method, key) CrudLogger.logger.info "\nSummary: Method: #{method}, Key: #{key}" @table_operations[method][key].each do |table_name, operations| CrudLogger.logger.info "#{table_name} - #{operations.join(", ")}" end end |
#table_operations_present?(method, key) ⇒ Boolean
45 46 47 48 49 50 |
# File 'lib/rails/crud/tools/crud_operations.rb', line 45 def table_operations_present?(method, key) return false if @table_operations[method].nil? return false if @table_operations[method][key].nil? !@table_operations[method][key].empty? end |