Class: ForestAdminDatasourceCustomizer::DSL::ActionBuilder
- Inherits:
-
Object
- Object
- ForestAdminDatasourceCustomizer::DSL::ActionBuilder
- Defined in:
- lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb
Overview
ActionBuilder provides a fluent DSL for building custom actions
Instance Method Summary collapse
-
#description(text) ⇒ Object
Set the action description.
-
#execute(&block) ⇒ Object
Define the action execution logic The block is executed in the context of an ExecutionContext which provides helper methods like success, error, file, etc.
-
#form(&block) ⇒ Object
Define the action form using FormBuilder DSL.
-
#generates_file! ⇒ Object
Mark action as generating a file.
-
#initialize(scope:) ⇒ ActionBuilder
constructor
A new instance of ActionBuilder.
-
#submit_button_label(label) ⇒ Object
Set custom submit button label.
-
#to_action ⇒ Decorators::Action::BaseAction
Build and return the BaseAction instance.
Constructor Details
#initialize(scope:) ⇒ ActionBuilder
Returns a new instance of ActionBuilder.
30 31 32 33 34 35 36 37 |
# File 'lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb', line 30 def initialize(scope:) @scope = normalize_scope(scope) @form_fields = nil @execute_block = nil @description = nil @submit_button_label = nil @generate_file = false end |
Instance Method Details
#description(text) ⇒ Object
Set the action description
41 42 43 |
# File 'lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb', line 41 def description(text) @description = text end |
#execute(&block) ⇒ Object
Define the action execution logic The block is executed in the context of an ExecutionContext which provides helper methods like success, error, file, etc.
69 70 71 72 73 74 75 |
# File 'lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb', line 69 def execute(&block) @execute_block = proc do |context, result_builder| executor = ExecutionContext.new(context, result_builder) executor.instance_eval(&block) executor.result end end |
#form(&block) ⇒ Object
Define the action form using FormBuilder DSL
58 59 60 61 62 |
# File 'lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb', line 58 def form(&block) form_builder = FormBuilder.new form_builder.instance_eval(&block) @form_fields = form_builder.fields end |
#generates_file! ⇒ Object
Mark action as generating a file
52 53 54 |
# File 'lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb', line 52 def generates_file! @generate_file = true end |
#submit_button_label(label) ⇒ Object
Set custom submit button label
47 48 49 |
# File 'lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb', line 47 def (label) @submit_button_label = label end |
#to_action ⇒ Decorators::Action::BaseAction
Build and return the BaseAction instance
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/forest_admin_datasource_customizer/dsl/builders/action_builder.rb', line 79 def to_action raise ArgumentError, 'execute block is required' unless @execute_block Decorators::Action::BaseAction.new( scope: @scope, form: @form_fields, is_generate_file: @generate_file, description: @description, submit_button_label: @submit_button_label, &@execute_block ) end |