Class: SolidObjects::ComponentsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- SolidObjects::ComponentsController
- Defined in:
- app/controllers/solid_objects/components_controller.rb,
sig/generated/controllers/solid_objects/components_controller.rbs
Instance Method Summary collapse
- #component_frame(registration, snapshot, rendered) ⇒ String
- #component_view_context ⇒ Object
- #newer_than_snapshot?(requested_revision, snapshot) ⇒ Boolean
- #requested_revision_key ⇒ Array[Integer]
- #show ⇒ void
Instance Method Details
#component_frame(registration, snapshot, rendered) ⇒ String
68 69 70 71 |
# File 'app/controllers/solid_objects/components_controller.rb', line 68 def component_frame(registration, snapshot, rendered) revision = "#{snapshot.instance_id}:#{snapshot.revision}" %(<turbo-frame id="#{registration.dom_id}" data-solid-objects-revision="#{revision}" data-solid-objects-refresh="#{registration.refresh_method}">#{rendered}</turbo-frame>).html_safe end |
#component_view_context ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/solid_objects/components_controller.rb', line 57 def component_view_context if defined?(Rails) && Rails.application prepend_view_path(*Rails.application.paths["app/views"].existent) end view_context.tap do |context| context.extend(Rails.application.helpers) if defined?(Rails) && Rails.application end end |
#newer_than_snapshot?(requested_revision, snapshot) ⇒ Boolean
52 53 54 |
# File 'app/controllers/solid_objects/components_controller.rb', line 52 def newer_than_snapshot?(requested_revision, snapshot) (requested_revision <=> [ snapshot.instance_id, snapshot.revision ]) == 1 end |
#requested_revision_key ⇒ Array[Integer]
43 44 45 46 47 48 49 |
# File 'app/controllers/solid_objects/components_controller.rb', line 43 def requested_revision_key instance_id = Integer(params.fetch(:instance_id), 10) revision = Integer(params.fetch(:revision), 10) raise ArgumentError if instance_id.negative? || revision.negative? [ instance_id, revision ] end |
#show ⇒ void
This method returns an undefined value.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/solid_objects/components_controller.rb', line 10 def show registration = ComponentRegistration.from_token( params.require(:token) ) requested_revision = requested_revision_key snapshot = ActorSnapshot.new(registration.reference) return head :conflict if newer_than_snapshot?(requested_revision, snapshot) = SolidObjects .configuration . .call(controller: self) rendered = ComponentRenderer.new( snapshot:, registration:, view_context: component_view_context, authorization_context: ).call response.headers["Cache-Control"] = "private, no-store" render html: component_frame(registration, snapshot, rendered) rescue Unauthorized head :forbidden rescue UnknownComponent head :not_found rescue ActionController::ParameterMissing, ArgumentError, InvalidComponentToken head :bad_request end |