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
115 116 117 118 119 120 121 |
# File 'lib/plutonium/action/interactive.rb', line 115 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/plutonium/action/interactive.rb', line 47 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
100 101 102 103 104 105 106 107 |
# File 'lib/plutonium/action/interactive.rb', line 100 def self.(action_type) { bulk_action: action_type == :interactive_collection_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
78 79 80 81 82 83 84 85 86 |
# File 'lib/plutonium/action/interactive.rb', line 78 def self.determine_action_type(attribute_names) if attribute_names.include?(:resource) :interactive_record_action elsif attribute_names.include?(:resources) :interactive_collection_action else :interactive_resource_action end end |
.determine_input_fields(attribute_names) ⇒ Array<Symbol>
Determine the input fields for the action
92 93 94 |
# File 'lib/plutonium/action/interactive.rb', line 92 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
70 71 72 |
# File 'lib/plutonium/action/interactive.rb', line 70 def self.symbolized_attribute_names(interaction) interaction.attribute_names.map(&:to_sym) end |