Module: Dommy::Resources
- Defined in:
- lib/dommy/resources.rb
Overview
The single interface through which the lightweight test browser resolves
external resources — both <script src> loads and fetch / XHR. A real
browser routes both through one network layer, so Dommy does too: a
Resources adapter answers #get / #request with a Response, and the
same adapter can be installed as the window's fetch handler.
An adapter returns nil from #request when it does not serve a URL, so
callers fall through (to the next adapter in a chain, or to the stub maps
behind window.fetch). Built-in adapters: static, file_system, chain.
Dommy::Rack::Resources (in dommy-rack) serves a Rack app.
Defined Under Namespace
Modules: Pathing Classes: Chain, FetchHandler, FileSystem, Response, Static
Class Method Summary collapse
-
.chain(*adapters) ⇒ Object
Try each adapter in order; the first non-nil Response wins.
-
.file_system(root:, base_url: "/") ⇒ Object
Serve files under
rootfor URLs whose path starts withbase_url. -
.static(map) ⇒ Object
An in-memory adapter.
Class Method Details
.chain(*adapters) ⇒ Object
Try each adapter in order; the first non-nil Response wins.
37 |
# File 'lib/dommy/resources.rb', line 37 def chain(*adapters) = Chain.new(adapters) |
.file_system(root:, base_url: "/") ⇒ Object
Serve files under root for URLs whose path starts with base_url.
file_system(root: "dist", base_url: "/assets") maps the request path
/assets/app.js to the file dist/app.js. Missing files return nil.
34 |
# File 'lib/dommy/resources.rb', line 34 def file_system(root:, base_url: "/") = FileSystem.new(root, base_url) |
.static(map) ⇒ Object
An in-memory adapter. map keys are matched against the request URL as
given AND its path component, so { "/app.js" => "..." } serves both
/app.js and http://host/app.js. A value is either a body String or a
Hash with "status" / "headers" / "body" / "content_type".
29 |
# File 'lib/dommy/resources.rb', line 29 def static(map) = Static.new(map) |