Class: Inertia::RequestContext
- Inherits:
-
Object
- Object
- Inertia::RequestContext
- Defined in:
- lib/inertia/request_context.rb
Overview
Encapsulates request-specific context for Inertia partial reloads.
Instance Method Summary collapse
-
#initialize(request, component:) ⇒ RequestContext
constructor
Creates a new request context.
-
#once_prop_excluded?(prop_name) ⇒ Boolean
Checks if a once prop should be excluded based on the client's cached props.
-
#partial_render? ⇒ Boolean
Checks if this is a partial reload request for the current component.
-
#prop_status(prop_name) ⇒ Symbol
Determines the inclusion status of a prop based on partial reload headers.
-
#url ⇒ String
Returns the full request path including query string.
Constructor Details
#initialize(request, component:) ⇒ RequestContext
Creates a new request context.
14 15 16 17 |
# File 'lib/inertia/request_context.rb', line 14 def initialize(request, component:) @request = request @component = component end |
Instance Method Details
#once_prop_excluded?(prop_name) ⇒ Boolean
Checks if a once prop should be excluded based on the client's cached props.
57 58 59 |
# File 'lib/inertia/request_context.rb', line 57 def once_prop_excluded?(prop_name) except_once.include?(prop_name) end |
#partial_render? ⇒ Boolean
Checks if this is a partial reload request for the current component.
63 64 65 |
# File 'lib/inertia/request_context.rb', line 63 def partial_render? partial_component == @component end |
#prop_status(prop_name) ⇒ Symbol
Determines the inclusion status of a prop based on partial reload headers.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inertia/request_context.rb', line 32 def prop_status(prop_name) return :unspecified unless partial_render? is_excluded = partial_except.any? do |except_prop_name| prop_name == except_prop_name || (prop_name.start_with?(except_prop_name) && prop_name.start_with?("#{except_prop_name}.")) end return :excluded if is_excluded return :requested if partial_only.empty? && partial_except.any? return :unspecified if partial_only.empty? is_included_in_partial_reload = partial_only.any? do |only_prop_name| prop_name == only_prop_name || (only_prop_name.start_with?(prop_name) && only_prop_name.start_with?("#{prop_name}.")) || (prop_name.start_with?(only_prop_name) && prop_name.start_with?("#{only_prop_name}.")) end is_included_in_partial_reload ? :requested : :excluded end |
#url ⇒ String
Returns the full request path including query string.
21 22 23 |
# File 'lib/inertia/request_context.rb', line 21 def url @request.fullpath end |