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 Method Summary collapse
-
#any_target?(tested_target) ⇒ Boolean
Determine if the
tested_target
is the current target for a successful or failed request. -
#fail_target ⇒ String?
The CSS selector for the fragment Unpoly will update if the request fails.
-
#fail_target?(tested_target) ⇒ Boolean
Determine if the
tested_target
is the current target for a failed request. -
#initialize(request) ⇒ Inspector
constructor
private
A new instance of Inspector.
- #query_target(actual_target, tested_target) ⇒ Object private
-
#set_title(response, new_title) ⇒ Object
Set the page title.
-
#target ⇒ String?
The actual target as requested by Unpoly.
-
#target?(tested_target) ⇒ Boolean
Identify if the
tested_target
will 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 ⇒ String?
The name attribute of the form field that triggered the validation.
Constructor Details
#initialize(request) ⇒ Inspector
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Inspector.
21 22 23 |
# File 'lib/rack/unpoly/inspector.rb', line 21 def initialize(request) @request = request end |
Instance Method Details
#any_target?(tested_target) ⇒ Boolean
Determine if the tested_target
is the current target for a successful or failed request.
66 67 68 |
# File 'lib/rack/unpoly/inspector.rb', line 66 def any_target?(tested_target) target?(tested_target) || fail_target?(tested_target) end |
#fail_target ⇒ String?
The CSS selector for the fragment Unpoly will update if the request fails. Requires Unpoly >= 0.50
51 52 53 |
# File 'lib/rack/unpoly/inspector.rb', line 51 def fail_target get_header("HTTP_X_UP_FAIL_TARGET") end |
#fail_target?(tested_target) ⇒ Boolean
Determine if the tested_target
is the current target for a failed request. Requires Unpoly >= 0.50
59 60 61 |
# File 'lib/rack/unpoly/inspector.rb', line 59 def fail_target?(tested_target) query_target(fail_target, tested_target) end |
#query_target(actual_target, tested_target) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rack/unpoly/inspector.rb', line 97 def query_target(actual_target, tested_target) 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.
75 76 77 |
# File 'lib/rack/unpoly/inspector.rb', line 75 def set_title(response, new_title) response.headers["X-Up-Title"] = new_title end |
#target ⇒ String?
The actual target as requested by Unpoly.
43 44 45 |
# File 'lib/rack/unpoly/inspector.rb', line 43 def target get_header("HTTP_X_UP_TARGET") end |
#target?(tested_target) ⇒ Boolean
Identify if the tested_target
will match the actual target requested.
36 37 38 |
# File 'lib/rack/unpoly/inspector.rb', line 36 def target?(tested_target) query_target(target, tested_target) end |
#unpoly? ⇒ Boolean Also known as: up?
Determine if this is an Unpoly request.
27 28 29 |
# File 'lib/rack/unpoly/inspector.rb', line 27 def unpoly? target.to_s.strip != "" end |
#validate? ⇒ Boolean
Determine if this is a validate request.
82 83 84 |
# File 'lib/rack/unpoly/inspector.rb', line 82 def validate? validate_name.to_s.strip != "" end |
#validate_name ⇒ String?
The name attribute of the form field that triggered the validation.
90 91 92 |
# File 'lib/rack/unpoly/inspector.rb', line 90 def validate_name get_header("HTTP_X_UP_VALIDATE") end |