Class: Plutonium::Action::Interactive::Factory
- Inherits:
-
Object
- Object
- Plutonium::Action::Interactive::Factory
- Defined in:
- lib/plutonium/action/interactive.rb
Overview
Factory for creating Interactive actions
Class Method Summary collapse
-
.build_route_options(name, action_type, immediate) ⇒ RouteOptions
Build the route options for the action.
-
.create(name, interaction:, **options) ⇒ Interactive
Create a new Interactive action based on the interaction type.
-
.determine_action_options(action_type) ⇒ Hash
Determine the action options based on the action type.
-
.determine_action_type(attribute_names) ⇒ Symbol
Determine the action type based on the interaction's attributes.
-
.determine_input_fields(attribute_names) ⇒ Array<Symbol>
Determine the input fields for the action.
-
.symbolized_attribute_names(interaction) ⇒ Array<Symbol>
Get symbolized attribute names for the interaction.
Class Method Details
.build_route_options(name, action_type, immediate) ⇒ RouteOptions
Build the route options for the action
125 126 127 128 129 130 131 |
# File 'lib/plutonium/action/interactive.rb', line 125 def self.(name, action_type, immediate) RouteOptions.new( method: immediate ? :post : :get, action: action_type, interactive_action: name ) end |
.create(name, interaction:, **options) ⇒ Interactive
Create a new Interactive action based on the interaction type
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/plutonium/action/interactive.rb', line 57 def self.create(name, interaction:, **) attribute_names = symbolized_attribute_names(interaction) action_type = determine_action_type(attribute_names) input_fields = determine_input_fields(attribute_names) = (action_type) immediate = .fetch(:immediate) { input_fields.blank? } = (name, action_type, immediate) Interactive.new( name, interaction: interaction, immediate: immediate, route_options: , turbo: interaction.turbo, **, ** ) end |
.determine_action_options(action_type) ⇒ Hash
Determine the action options based on the action type
110 111 112 113 114 115 116 117 |
# File 'lib/plutonium/action/interactive.rb', line 110 def self.(action_type) { bulk_action: action_type == :interactive_bulk_action, record_action: action_type == :interactive_record_action, collection_record_action: action_type == :interactive_record_action, resource_action: action_type == :interactive_resource_action } end |
.determine_action_type(attribute_names) ⇒ Symbol
Determine the action type based on the interaction's attributes
88 89 90 91 92 93 94 95 96 |
# File 'lib/plutonium/action/interactive.rb', line 88 def self.determine_action_type(attribute_names) if attribute_names.include?(:resource) :interactive_record_action elsif attribute_names.include?(:resources) :interactive_bulk_action else :interactive_resource_action end end |
.determine_input_fields(attribute_names) ⇒ Array<Symbol>
Determine the input fields for the action
102 103 104 |
# File 'lib/plutonium/action/interactive.rb', line 102 def self.determine_input_fields(attribute_names) attribute_names - [:resource, :resources] end |
.symbolized_attribute_names(interaction) ⇒ Array<Symbol>
Get symbolized attribute names for the interaction
80 81 82 |
# File 'lib/plutonium/action/interactive.rb', line 80 def self.symbolized_attribute_names(interaction) interaction.attribute_names.map(&:to_sym) end |