Class: Rack::Unpoly::Inspector
- Inherits:
-
Object
- Object
- Rack::Unpoly::Inspector
- Extended by:
- Forwardable
- Defined in:
- lib/rack/unpoly/inspector.rb
Overview
Easily inspect the Unpoly environment of the current request. Inspectors are not normally instantiated by users, but accessed through env or one of the convenience wrappers for Roda and Sinatra.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#any_target?(tested_target) ⇒ Boolean
Determine if the provided target is the current target for a successful or failed request.
-
#fail_target ⇒ Object
The CSS selector for the fragment Unpoly will update if the request fails.
-
#fail_target?(tested_target) ⇒ Boolean
Determine if the provided target is the current target for a failed request.
-
#initialize(request) ⇒ Inspector
constructor
:nodoc:.
-
#query_target(actual_target, tested_target) ⇒ Object
:nodoc:.
-
#set_title(response, new_title) ⇒ Object
Set the page title.
-
#target ⇒ Object
The actual target as requested by Unpoly.
-
#target?(tested_target) ⇒ Boolean
Identify if the
tested_targetwill match the actual target requested. -
#unpoly? ⇒ Boolean
(also: #up?)
Determine if this is an Unpoly request.
-
#validate? ⇒ Boolean
Determine if this is a validate request.
-
#validate_name ⇒ Object
The name attribute of the form field that triggered the validation.
Constructor Details
#initialize(request) ⇒ Inspector
:nodoc:
17 18 19 |
# File 'lib/rack/unpoly/inspector.rb', line 17 def initialize(request) # :nodoc: @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
:nodoc:
15 16 17 |
# File 'lib/rack/unpoly/inspector.rb', line 15 def request @request end |
Instance Method Details
#any_target?(tested_target) ⇒ Boolean
Determine if the provided target is the current target for a successful or failed request.
50 51 52 |
# File 'lib/rack/unpoly/inspector.rb', line 50 def any_target?(tested_target) target?(tested_target) || fail_target?(tested_target) end |
#fail_target ⇒ Object
The CSS selector for the fragment Unpoly will update if the request fails. Requires Unpoly >= 0.50
39 40 41 |
# File 'lib/rack/unpoly/inspector.rb', line 39 def fail_target get_header("HTTP_X_UP_FAIL_TARGET") end |
#fail_target?(tested_target) ⇒ Boolean
Determine if the provided target is the current target for a failed request. Requires Unpoly >= 0.50
45 46 47 |
# File 'lib/rack/unpoly/inspector.rb', line 45 def fail_target?(tested_target) query_target(fail_target, tested_target) end |
#query_target(actual_target, tested_target) ⇒ Object
:nodoc:
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rack/unpoly/inspector.rb', line 70 def query_target(actual_target, tested_target) # :nodoc: if up? if actual_target == tested_target true elsif actual_target == "html" true elsif actual_target == "body" !%w(head title meta).include?(tested_target) else false end else true end end |
#set_title(response, new_title) ⇒ Object
Set the page title.
55 56 57 |
# File 'lib/rack/unpoly/inspector.rb', line 55 def set_title(response, new_title) response.headers["X-Up-Title"] = new_title end |
#target ⇒ Object
The actual target as requested by Unpoly.
33 34 35 |
# File 'lib/rack/unpoly/inspector.rb', line 33 def target get_header("HTTP_X_UP_TARGET") end |
#target?(tested_target) ⇒ Boolean
Identify if the tested_target will match the actual target requested.
28 29 30 |
# File 'lib/rack/unpoly/inspector.rb', line 28 def target?(tested_target) query_target(target, tested_target) end |
#unpoly? ⇒ Boolean Also known as: up?
Determine if this is an Unpoly request.
22 23 24 |
# File 'lib/rack/unpoly/inspector.rb', line 22 def unpoly? target.to_s.strip != "" end |
#validate? ⇒ Boolean
Determine if this is a validate request.
60 61 62 |
# File 'lib/rack/unpoly/inspector.rb', line 60 def validate? validate_name.to_s.strip != "" end |
#validate_name ⇒ Object
The name attribute of the form field that triggered the validation.
66 67 68 |
# File 'lib/rack/unpoly/inspector.rb', line 66 def validate_name get_header("HTTP_X_UP_VALIDATE") end |