Class: DbdocEngine::DbDesignDynamicTableHandlerService

Inherits:
Object
  • Object
show all
Defined in:
app/services/dbdoc_engine/db_design_dynamic_table_handler_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller_context, table_params, table = nil) ⇒ DbDesignDynamicTableHandlerService

Returns a new instance of DbDesignDynamicTableHandlerService.



4
5
6
7
8
# File 'app/services/dbdoc_engine/db_design_dynamic_table_handler_service.rb', line 4

def initialize(controller_context, table_params, table = nil)
  @controller = controller_context               # Reference to the controller instance
  @table_params = table_params                   # Table parameters from the controller
  @table = table                                 # Existing table object (optional, for update)
end

Instance Method Details

#create ⇒ Object

Handles table creation operation



11
12
13
14
15
16
17
18
19
20
# File 'app/services/dbdoc_engine/db_design_dynamic_table_handler_service.rb', line 11

def create
  result = service.create_table # Call service to create the table

  if result[:success]
    @controller.flash[:notice] = I18n.t("dbdoc.table_creation") # Success message
    @controller.redirect_to @controller.dbdoc_admin_db_design_dynamic_tables_path # Redirect to the table list
  else
    handle_failure(result, :new) # Handle failure (render 'new' view)
  end
end

#update ⇒ Object

Handles table update operation



23
24
25
26
27
28
29
30
31
32
# File 'app/services/dbdoc_engine/db_design_dynamic_table_handler_service.rb', line 23

def update
  result = service.update_table(@table) # Call service to update the table

  if result[:success]
    @controller.flash[:notice] = I18n.t("dbdoc.table_updation") # Success message
    @controller.redirect_to @controller.dbdoc_admin_db_design_dynamic_tables_path # Redirect to the table list
  else
    handle_failure(result, :edit) # Handle failure (render 'edit' view)
  end
end