Class: ViewComponentReducible::DispatchController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ViewComponentReducible::DispatchController
- Defined in:
- lib/view_component_reducible/dispatch_controller.rb
Overview
Rails controller entry for dispatch requests.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.vcr_adapter(adapter_class = nil) ⇒ Class?
12 13 14 15 16 |
# File 'lib/view_component_reducible/dispatch_controller.rb', line 12 def self.vcr_adapter(adapter_class = nil) return @vcr_adapter if adapter_class.nil? @vcr_adapter = adapter_class end |
Instance Method Details
#call ⇒ void
This method returns an undefined value.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/view_component_reducible/dispatch_controller.rb', line 19 def call adapter_class = self.class.vcr_adapter || ViewComponentReducible.config.adapter adapter = ViewComponentReducible.config.adapter_for(self, adapter_class: adapter_class) envelope = adapter.load(request:) msg = ViewComponentReducible::Msg.from_params(params) target_path = params.fetch('vcr_target_path', envelope['path']) runtime = ViewComponentReducible::Runtime.new new_envelope, html = runtime.call( envelope:, msg:, target_path:, controller: self ) signed = adapter.dump(new_envelope, request:) if params['vcr_partial'] == '1' partial_html = runtime.render_target(envelope: new_envelope, target_path:, controller: self) response.set_header('X-VCR-State', signed) render html: partial_html, content_type: 'text/html' else render html: ViewComponentReducible::Dispatch.inject_state(html, signed), content_type: 'text/html' end rescue ActiveSupport::MessageVerifier::InvalidSignature render status: 400, plain: 'Invalid state signature' end |