Introduce WebPipe::Pipe and make the DSL optional #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit is a vast internal refactor of the whole library plus the
addition of new features. While the public API remains
backward-compatible, the core functionality has been extracted to be
independent of the DSL.
We were already halfway to making the DSL a pure convenience layer.
WebPipe::App
already gave us the option to build rack applications byplugging operations, but we missed the opportunity to add middlewares or
inspect both operations and middlewares.
WebPipe::Pipe
is a new addition representing the top abstraction ofthe library, besides the DSL, which only adds a thin layer of
convenience. An instance of it has methods to plug operations, use
middlewares and inspect everything. All the other nifty features, say
composing other pipes, are also available. The DSL will only
transparently delegate to instances of it.
A
WebPipe::Pipe
instance is the rack application itself. As with thecase of
WebPipe::Conn
, it's an immutable class: i.e., methods like#plug
or#use
will return new instances every time.In the process, we've made two small additions related to how pipes are
composed. In the case of plugs, we allow anything responding to
#to_proc
(asWebPipe::Pipe#call
belongs to the required rackinterface). For middlewares, we remove ad-hoc checking for a
WebPipe
class and instead duck type on a
#to_middlewares
method (implementedon
WebPipe::Pipe
and delegated from the DSL).For instance, the following rack application written through the DSL:
is exactly equivalent to:
WebPipe::Pipe.new
accepts to parameterscontainer:
&context:
thatare given on plug resolution. The
container
parameter isself-explanatory.
context:
represents the object expected to implementmethods matching plug names when no specification is given (on the DSL,
that's the class including the
WebPipe
module).Other minor changes made during the refactor:
sanitization)