web_pipe 0.13.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +29 -0
- data/Gemfile +2 -2
- data/README.md +18 -11
- data/docs/building_a_rack_application.md +1 -1
- data/docs/composing_applications.md +4 -4
- data/docs/connection_struct/configuring_the_connection_struct.md +4 -4
- data/docs/connection_struct/halting_the_pipe.md +17 -19
- data/docs/connection_struct/sharing_data_downstream.md +9 -8
- data/docs/connection_struct.md +22 -19
- data/docs/design_model.md +10 -9
- data/docs/dsl_free_usage.md +85 -14
- data/docs/extensions/container.md +9 -10
- data/docs/extensions/cookies.md +4 -2
- data/docs/extensions/dry_schema.md +5 -4
- data/docs/extensions/flash.md +9 -11
- data/docs/extensions/{dry_view.md → hanami_view.md} +20 -22
- data/docs/extensions/not_found.md +40 -0
- data/docs/extensions/params.md +6 -4
- data/docs/extensions/rails.md +31 -38
- data/docs/extensions/redirect.md +5 -4
- data/docs/extensions/router_params.md +5 -5
- data/docs/extensions/session.md +4 -4
- data/docs/extensions/url.md +6 -6
- data/docs/extensions.md +5 -6
- data/docs/introduction.md +7 -7
- data/docs/plugging_operations/composing_operations.md +3 -3
- data/docs/plugging_operations/injecting_operations.md +4 -4
- data/docs/plugging_operations/inspecting_operations.md +24 -0
- data/docs/plugging_operations/resolving_operations.md +3 -3
- data/docs/plugging_operations.md +3 -3
- data/docs/plugs/config.md +1 -1
- data/docs/plugs/content_type.md +2 -1
- data/docs/plugs.md +6 -7
- data/docs/recipes/hanami_2_and_dry_rb_integration.md +12 -0
- data/docs/recipes/hanami_router_integration.md +3 -1
- data/docs/recipes/using_all_restful_methods.md +6 -5
- data/docs/testing.md +64 -0
- data/docs/using_rack_middlewares/composing_middlewares.md +2 -3
- data/docs/using_rack_middlewares/injecting_middlewares.md +6 -6
- data/docs/using_rack_middlewares/inspecting_middlewares.md +35 -0
- data/docs/using_rack_middlewares.md +6 -6
- data/lib/web_pipe/app.rb +22 -25
- data/lib/web_pipe/conn.rb +0 -1
- data/lib/web_pipe/conn_support/builder.rb +0 -7
- data/lib/web_pipe/conn_support/composition.rb +3 -26
- data/lib/web_pipe/conn_support/errors.rb +5 -5
- data/lib/web_pipe/conn_support/headers.rb +1 -50
- data/lib/web_pipe/conn_support/types.rb +3 -3
- data/lib/web_pipe/dsl/builder.rb +10 -19
- data/lib/web_pipe/dsl/class_context.rb +15 -40
- data/lib/web_pipe/dsl/instance_context.rb +53 -0
- data/lib/web_pipe/extensions/container/container.rb +2 -15
- data/lib/web_pipe/extensions/cookies/cookies.rb +2 -31
- data/lib/web_pipe/extensions/dry_schema/dry_schema.rb +2 -56
- data/lib/web_pipe/extensions/flash/flash.rb +2 -32
- data/lib/web_pipe/extensions/hanami_view/hanami_view.rb +67 -0
- data/lib/web_pipe/extensions/not_found/not_found.rb +26 -0
- data/lib/web_pipe/extensions/params/params.rb +2 -63
- data/lib/web_pipe/extensions/rails/rails.rb +2 -123
- data/lib/web_pipe/extensions/redirect/redirect.rb +2 -20
- data/lib/web_pipe/extensions/router_params/router_params.rb +1 -39
- data/lib/web_pipe/extensions/session/session.rb +2 -25
- data/lib/web_pipe/extensions/url/url.rb +2 -5
- data/lib/web_pipe/pipe.rb +229 -0
- data/lib/web_pipe/plug.rb +31 -65
- data/lib/web_pipe/plugs/config.rb +0 -2
- data/lib/web_pipe/plugs/content_type.rb +0 -2
- data/lib/web_pipe/rack_support/app_with_middlewares.rb +3 -26
- data/lib/web_pipe/rack_support/middleware.rb +2 -2
- data/lib/web_pipe/rack_support/middleware_specification.rb +19 -48
- data/lib/web_pipe/test_support.rb +28 -0
- data/lib/web_pipe/types.rb +1 -3
- data/lib/web_pipe/version.rb +1 -1
- data/lib/web_pipe.rb +77 -17
- data/web_pipe.gemspec +1 -2
- metadata +16 -9
- data/docs/recipes/dry_rb_integration.md +0 -18
- data/lib/web_pipe/dsl/dsl_context.rb +0 -85
- data/lib/web_pipe/dsl/instance_methods.rb +0 -114
- data/lib/web_pipe/extensions/dry_view/dry_view.rb +0 -158
@@ -4,63 +4,9 @@ require 'web_pipe'
|
|
4
4
|
|
5
5
|
WebPipe.load_extensions(:params)
|
6
6
|
|
7
|
-
|
7
|
+
# :nodoc:
|
8
8
|
module WebPipe
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# This extension provides a simple integration with `dry-schema`
|
12
|
-
# library to streamline param sanitization.
|
13
|
-
#
|
14
|
-
# On its own, the library just provides with a
|
15
|
-
# `Conn#sanitized_params` method, which will return what is set into
|
16
|
-
# config's `:sanitized_params` key.
|
17
|
-
#
|
18
|
-
# This key in config is what will be populated by `SanitizeParams` plug. It
|
19
|
-
# takes as arguments the `dry-schema` schema that will be applied to
|
20
|
-
# `Conn#params` and an error handler taking `Conn` instance and the validation
|
21
|
-
# result:
|
22
|
-
#
|
23
|
-
# @example
|
24
|
-
# require 'web_pipe'
|
25
|
-
#
|
26
|
-
# WebPipe.load_extensions(:dry_schema)
|
27
|
-
#
|
28
|
-
# class App
|
29
|
-
# include WebPipe
|
30
|
-
#
|
31
|
-
# Schema = Dry::Schema.Params do
|
32
|
-
# required(:name).filled(:string)
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# plug :sanitize_params, WebPipe::Plugs::SanitizeParams.(
|
36
|
-
# Schema,
|
37
|
-
# ->(conn, result) { ... }
|
38
|
-
# )
|
39
|
-
# plug(:do_something_with_params) do |conn|
|
40
|
-
# DB.persist(:entity, conn.sanitized_params)
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# A common workflow is applying the same handler for all param
|
45
|
-
# sanitization across your application. This can be achieved configuring
|
46
|
-
# a `:param_sanitization_handler` in a upstream operation which can
|
47
|
-
# be composed downstream from any number of pipes. `SanitizeParams`
|
48
|
-
# will used configured handler if none is injected as
|
49
|
-
# argument.
|
50
|
-
#
|
51
|
-
# @example
|
52
|
-
# class App
|
53
|
-
# plug :sanitization_handler, ->(conn, result) { ... }
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# class Subapp
|
57
|
-
# Schema = Dry::Schema.Params { ... }
|
58
|
-
#
|
59
|
-
# plug :app, App.new
|
60
|
-
# plug :sanitize_params, WebPipe::Plugs::SanitizeParams.call(Schema)
|
61
|
-
# end
|
62
|
-
#
|
63
|
-
# @see https://dry-rb.org/gems/dry-schema/
|
9
|
+
# See the docs for the extension linked from the README.
|
64
10
|
module DrySchema
|
65
11
|
SANITIZED_PARAMS_KEY = :sanitized_params
|
66
12
|
|
@@ -3,39 +3,9 @@
|
|
3
3
|
require 'web_pipe/conn'
|
4
4
|
require 'web_pipe/conn_support/errors'
|
5
5
|
|
6
|
-
|
6
|
+
# :nodoc:
|
7
7
|
module WebPipe
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# require 'web_pipe'
|
12
|
-
# require 'rack/session/cookie'
|
13
|
-
# require 'rack-flash'
|
14
|
-
#
|
15
|
-
# WebPipe.load_extensions(:flash)
|
16
|
-
#
|
17
|
-
# class MyApp
|
18
|
-
# include WebPipe
|
19
|
-
#
|
20
|
-
# use :session, Rack::Session::Cookie, secret: 'secret'
|
21
|
-
# use :flash, Rack::Flash
|
22
|
-
#
|
23
|
-
# plug :add_to_flash, ->(conn) { conn.add_flash(:notice, 'Hello world') }
|
24
|
-
# plug :add_to_flash_now, ->(conn) { conn.add_flash_now(:notice_now, 'Hello world now') }
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# Usually, you will end up making `conn.flash` available to your view system:
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# <div class="notice"><%= flash[:notice] %></div>
|
31
|
-
#
|
32
|
-
# For this extension to be used, `Rack::Flash` middleware must be
|
33
|
-
# added to the stack (gem name is `rack-flash3`. This middleware in
|
34
|
-
# turns depend on `Rack::Session` middleware.
|
35
|
-
#
|
36
|
-
# This extension is a very simple wrapper around `Rack::Flash` API.
|
37
|
-
#
|
38
|
-
# @see https://github.com/nakajima/rack-flash
|
8
|
+
# See the docs for the extension linked from the README.
|
39
9
|
module Flash
|
40
10
|
RACK_FLASH_KEY = 'x-rack.flash'
|
41
11
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'web_pipe/types'
|
4
|
+
require 'web_pipe/conn'
|
5
|
+
require 'hanami/view'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module WebPipe
|
9
|
+
# See the docs for the extension linked from the README.
|
10
|
+
module DryView
|
11
|
+
# Where to find in {#config} request's view context generator.
|
12
|
+
VIEW_CONTEXT_KEY = :view_context
|
13
|
+
|
14
|
+
# Default request's view context
|
15
|
+
DEFAULT_VIEW_CONTEXT = ->(_conn) { Types::EMPTY_HASH }
|
16
|
+
|
17
|
+
# Sets string output of a view as response body.
|
18
|
+
#
|
19
|
+
# If the view is not a {Hanami::View} instance, it is resolved from
|
20
|
+
# the configured container.
|
21
|
+
#
|
22
|
+
# `kwargs` is used as the input for the view (the arguments that
|
23
|
+
# {Hanami::View#call} receives). If they doesn't contain an explicit
|
24
|
+
# `context:` key, it can be added through the injection of the
|
25
|
+
# result of a lambda present in context's `:view_context`.(see
|
26
|
+
# {Hanami::View::Context#with}).
|
27
|
+
#
|
28
|
+
# @param view_spec [Hanami::View, Any]
|
29
|
+
# @param kwargs [Hash] Arguments to pass along to `Hanami::View#call`
|
30
|
+
#
|
31
|
+
# @return WebPipe::Conn
|
32
|
+
def view(view_spec, **kwargs)
|
33
|
+
view_instance = view_instance(view_spec)
|
34
|
+
view_input = view_input(kwargs, view_instance)
|
35
|
+
|
36
|
+
set_response_body(
|
37
|
+
view_instance.call(
|
38
|
+
**view_input
|
39
|
+
).to_str
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def view_instance(view_spec)
|
46
|
+
return view_spec if view_spec.is_a?(Hanami::View)
|
47
|
+
|
48
|
+
fetch_config(:container)[view_spec]
|
49
|
+
end
|
50
|
+
|
51
|
+
def view_input(kwargs, view_instance)
|
52
|
+
return kwargs if kwargs.key?(:context)
|
53
|
+
|
54
|
+
context = view_instance
|
55
|
+
.config
|
56
|
+
.default_context
|
57
|
+
.with(
|
58
|
+
**fetch_config(
|
59
|
+
VIEW_CONTEXT_KEY, DEFAULT_VIEW_CONTEXT
|
60
|
+
).call(self)
|
61
|
+
)
|
62
|
+
kwargs.merge(context: context)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Conn.include(DryView)
|
67
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module WebPipe
|
5
|
+
# See the docs for the extension linked from the README.
|
6
|
+
module NotFound
|
7
|
+
# @api private
|
8
|
+
RESPONSE_BODY_STEP_CONFIG_KEY = :not_found_body_step
|
9
|
+
|
10
|
+
# Generates the not-found response
|
11
|
+
#
|
12
|
+
# @return [WebPipe::Conn::Halted]
|
13
|
+
# @see NotFound
|
14
|
+
def not_found
|
15
|
+
set_status(404)
|
16
|
+
.then do |conn|
|
17
|
+
response_body_step = conn.fetch_config(RESPONSE_BODY_STEP_CONFIG_KEY,
|
18
|
+
->(c) { c.set_response_body('Not found') })
|
19
|
+
|
20
|
+
response_body_step.call(conn)
|
21
|
+
end.halt
|
22
|
+
end
|
23
|
+
|
24
|
+
Conn.include(NotFound)
|
25
|
+
end
|
26
|
+
end
|
@@ -3,70 +3,9 @@
|
|
3
3
|
require 'web_pipe/types'
|
4
4
|
require 'web_pipe/extensions/params/params/transf'
|
5
5
|
|
6
|
-
|
6
|
+
# :nodoc:
|
7
7
|
module WebPipe
|
8
|
-
#
|
9
|
-
# transformations to the request parameters.
|
10
|
-
#
|
11
|
-
# When no transformations are given, {#params} just returns request
|
12
|
-
# parameters (both GET and POST) as a hash:
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# # http://www.example.com?foo=bar
|
16
|
-
# conn.params #=> { 'foo' => 'bar' }
|
17
|
-
#
|
18
|
-
# Further processing can be specified thanks to `dry-transformer` gem (you
|
19
|
-
# need to add it yourself to the Gemfile). All hash transformations
|
20
|
-
# in `dry-transformer` are available:
|
21
|
-
#
|
22
|
-
# @example
|
23
|
-
# # http://www.example.com?foo=bar
|
24
|
-
# conn.params([:deep_symbolize_keys]) #=> { foo: 'bar' }
|
25
|
-
#
|
26
|
-
# Extra needed arguments can be provided as an array:
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# # http://www.example.com?foo=bar&zoo=zoo
|
30
|
-
# conn.params([:deep_symbolize_keys, [:reject_keys, [:zoo]]) #=> { foo: 'bar' }
|
31
|
-
#
|
32
|
-
# Instead of injecting transformations at the moment `#params` is
|
33
|
-
# called, you can configure them to be automatically used.
|
34
|
-
#
|
35
|
-
# @example
|
36
|
-
# # http://www.example.com?foo=bar
|
37
|
-
# conn.
|
38
|
-
# add_config(:param_transformations, [:deep_symbolize_keys]).
|
39
|
-
# params #=> { foo: 'bar' }
|
40
|
-
#
|
41
|
-
# You can register your own transformation functions:
|
42
|
-
#
|
43
|
-
# @example
|
44
|
-
# # http://www.example.com?foo=bar
|
45
|
-
# fake = ->(_params) { { fake: :params } }
|
46
|
-
# WebPipe::Params::Transf.register(:fake, fake)
|
47
|
-
# conn.params([:fake]) #=> { fake: :params }
|
48
|
-
#
|
49
|
-
# Your own transformation functions can depend on the {Conn}
|
50
|
-
# instance at the moment of execution. For that, just place it as the
|
51
|
-
# last argument of the function and it will be curried automatically:
|
52
|
-
#
|
53
|
-
# @example
|
54
|
-
# # http://www.example.com?foo=bar
|
55
|
-
# add_name = ->(params, conn) { params.merge(name: conn.fetch(:name)) }
|
56
|
-
# WebPipe::Params::Transf.register(:add_name, add_name)
|
57
|
-
# conn.
|
58
|
-
# add(:name, 'Joe').
|
59
|
-
# params([:deep_symbolize_keys, :add_name]) #=> { foo: 'bar', name: 'Joe' }
|
60
|
-
#
|
61
|
-
# Inline transformations can also be provided:
|
62
|
-
#
|
63
|
-
# @example
|
64
|
-
# # http://www.example.com?foo=bar
|
65
|
-
# fake = ->(_params) { { fake: :params } }
|
66
|
-
# conn.
|
67
|
-
# params(fake) #=> { fake: :params }
|
68
|
-
#
|
69
|
-
# @see https://github.com/dry-rb/dry-transformer
|
8
|
+
# See the docs for the extension linked from the README.
|
70
9
|
module Params
|
71
10
|
# Key where configured transformations are set
|
72
11
|
PARAM_TRANSFORMATION_KEY = :param_transformations
|
@@ -2,130 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'web_pipe/conn'
|
4
4
|
|
5
|
-
|
5
|
+
# :nodoc:
|
6
6
|
module WebPipe
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# The first two things to keep in mind in order to integrate with Rails is
|
10
|
-
# that {WebPipe} instances are Rack applications and that rails router can
|
11
|
-
# perfectly dispatch to a rack application. For example:
|
12
|
-
#
|
13
|
-
# ```ruby
|
14
|
-
# # config/routes.rb
|
15
|
-
# get '/my_route', to: MyRoute.new
|
16
|
-
#
|
17
|
-
# # app/controllers/my_route.rb
|
18
|
-
# class MyRoute
|
19
|
-
# include WebPipe
|
20
|
-
#
|
21
|
-
# plug :set_response_body
|
22
|
-
#
|
23
|
-
# private
|
24
|
-
#
|
25
|
-
# def set_response_body(conn)
|
26
|
-
# conn.set_response_body('Hello, World!')
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
# ```
|
30
|
-
#
|
31
|
-
# In order to do something like the previous example you don't need to enable
|
32
|
-
# this extension. Notice that rails took care of dispatching the request to
|
33
|
-
# our {WebPipe} rack application, which was then responsible for generating the
|
34
|
-
# response. In this case, it used a simple call to
|
35
|
-
# {WebPipe::Conn#set_response_body}.
|
36
|
-
#
|
37
|
-
# It's quite possible that you don't need more than that in terms of rails
|
38
|
-
# integration. Of course, surely you want something more elaborate to generate
|
39
|
-
# responses. For that, you can use the view or template system you like. One
|
40
|
-
# option that will play specially well here is `dry-view`, which integrates
|
41
|
-
# itself easily with Rails. Furthermore, we have a tailored `dry_view`
|
42
|
-
# extension.
|
43
|
-
#
|
44
|
-
# You need to use `:rails` extension if:
|
45
|
-
#
|
46
|
-
# - You want to use `action_view` as rendering system.
|
47
|
-
# - You want to use rails url helpers from your {WebPipe} application.
|
48
|
-
# - You want to use controller helpers from your {WebPipe} application.
|
49
|
-
#
|
50
|
-
# Rails responsibilities for controlling the request/response cycle and the
|
51
|
-
# rendering process are a little bit tangled. For this reason, even if you
|
52
|
-
# want to use {WebPipe} applications instead of Rails controller actions you
|
53
|
-
# still have to use the typical top `ApplicationController` in order to define
|
54
|
-
# some behaviour for the view layer:
|
55
|
-
#
|
56
|
-
# - Which layout is applied to the template.
|
57
|
-
# - Which helpers will become available to the templates.
|
58
|
-
#
|
59
|
-
# By default, the controller in use is `ActionController::Base`, which means
|
60
|
-
# that no layout is applied and only built-in helpers (for example,
|
61
|
-
# `number_as_currency`) are available. You can change it via the
|
62
|
-
# `:rails_controller` configuration option.
|
63
|
-
#
|
64
|
-
# The main method that this extension adds to {WebPipe::Conn} is `#render`,
|
65
|
-
# which just delegates to the Rails implementation as you'd do in a typical
|
66
|
-
# rails controller. Remember that you can provide template instance variables
|
67
|
-
# through the keyword `:assigns`.
|
68
|
-
#
|
69
|
-
# ```ruby
|
70
|
-
# # config/routes.rb
|
71
|
-
# get '/articles', to: ArticlesIndex.new
|
72
|
-
#
|
73
|
-
# # app/controllers/application_controller.rb
|
74
|
-
# class ApplicationController < ActionController::Base
|
75
|
-
# # By default uses the layout in `layouts/application`
|
76
|
-
# end
|
77
|
-
#
|
78
|
-
# # app/controllers/articles_index.rb
|
79
|
-
# require 'web_pipe/plugs/config'
|
80
|
-
#
|
81
|
-
#
|
82
|
-
# WebPipe.load_extensions(:rails) # You can put it in an initializer
|
83
|
-
#
|
84
|
-
# class ArticlesIndex
|
85
|
-
# include WebPipe
|
86
|
-
#
|
87
|
-
# plug :config, WebPipe::Plugs::Config.(
|
88
|
-
# rails_controller: ApplicationController
|
89
|
-
# )
|
90
|
-
#
|
91
|
-
# def render(conn)
|
92
|
-
# conn.render(
|
93
|
-
# template: 'articles/index',
|
94
|
-
# assigns: { articles: Article.all }
|
95
|
-
# )
|
96
|
-
# end
|
97
|
-
# end
|
98
|
-
# ```
|
99
|
-
#
|
100
|
-
# Notice that we used the keyword `template:` instead of taking advantage of
|
101
|
-
# automatic template lookup. We did that way so that we don't have to create
|
102
|
-
# also an `ArticlesController`, but it's up to you. In the case of having an
|
103
|
-
# `ArticlesController` we could just do `conn.render(:index, assigns: {
|
104
|
-
# articles: Article.all })`.
|
105
|
-
#
|
106
|
-
# Besides, this extension provides with two other methods:
|
107
|
-
#
|
108
|
-
# - `url_helpers` returns Rails router url helpers.
|
109
|
-
# - `helpers` returns the associated controller helpers.
|
110
|
-
#
|
111
|
-
# In all the examples we have supposed that we are putting {WebPipe}
|
112
|
-
# applications within `app/controllers/` directory. However, remember you can
|
113
|
-
# put them wherever you like as long as you respect rails `autoload_paths`.
|
114
|
-
#
|
115
|
-
# Here you have a link to a very simple and contrived example of a rails
|
116
|
-
# application integrating `web_pipe`:
|
117
|
-
#
|
118
|
-
# https://github.com/waiting-for-dev/rails-web_pipe
|
119
|
-
#
|
120
|
-
# @see https://guides.rubyonrails.org/routing.html#routing-to-rack-applications
|
121
|
-
# @see https://dry-rb.org/gems/dry-view/
|
122
|
-
# @see https://github.com/dry-rb/dry-view/tree/master/examples/rails
|
123
|
-
# @see https://waiting-for-dev.github.io/web_pipe/docs/extensions/dry_view.html
|
124
|
-
# @see https://api.rubyonrails.org/v6.0.1/classes/ActionController/Renderer.html
|
125
|
-
# @see https://api.rubyonrails.org/v6.0.1/classes/ActionController/Renderer.html
|
126
|
-
# @see https://api.rubyonrails.org/v6.0.1/classes/ActionView/Helpers/UrlHelper.html
|
127
|
-
# @see https://api.rubyonrails.org/classes/ActionController/Helpers.html
|
128
|
-
# @see https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoload-paths
|
7
|
+
# See the docs for the extension linked from the README.
|
129
8
|
module Rails
|
130
9
|
def render(*args)
|
131
10
|
set_response_body(
|
@@ -2,27 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'web_pipe/types'
|
4
4
|
|
5
|
-
|
5
|
+
# :nodoc:
|
6
6
|
module WebPipe
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# This extensions adds a {#redirect} method to {Conn} which helps
|
10
|
-
# setting the `Location` header and the status code needed to
|
11
|
-
# instruct the browser to perform a redirect. By default, `302`
|
12
|
-
# status code is used.
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# require 'web_pipe'
|
16
|
-
#
|
17
|
-
# WebPipe.load_extensions(:redirect)
|
18
|
-
#
|
19
|
-
# class MyApp
|
20
|
-
# include WebPipe
|
21
|
-
#
|
22
|
-
# plug(:redirect) do |conn|
|
23
|
-
# conn.redirect('/', 301)
|
24
|
-
# end
|
25
|
-
# end
|
7
|
+
# See the docs for the extension linked from the README.
|
26
8
|
module Redirect
|
27
9
|
# Location header
|
28
10
|
LOCATION_HEADER = 'Location'
|
@@ -6,45 +6,7 @@ require 'web_pipe/types'
|
|
6
6
|
WebPipe.load_extensions(:params)
|
7
7
|
|
8
8
|
module WebPipe
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# This extension gives an opportunity for rack routers to modify
|
12
|
-
# {Conn#params} hash. This is useful so that they can provide *route
|
13
|
-
# parameters*, which are typically rendered as variables in routes
|
14
|
-
# definitions (e.g.: `/user/:id/edit`).
|
15
|
-
#
|
16
|
-
# It adds a `:router_params` transformation that, when used, will
|
17
|
-
# merged env's `router.params` in {Conn#params} hash. Choosing this
|
18
|
-
# name automatically integrates with `hanami-router`.
|
19
|
-
#
|
20
|
-
# When using this extension, `:params` extension is automatically enabled.
|
21
|
-
#
|
22
|
-
# @example
|
23
|
-
# require 'web_pipe'
|
24
|
-
#
|
25
|
-
# WebPipe.load_extensions(:router_params)
|
26
|
-
#
|
27
|
-
# class MyApp
|
28
|
-
# include WebPipe
|
29
|
-
#
|
30
|
-
# plug :config
|
31
|
-
# plug :get_params
|
32
|
-
#
|
33
|
-
# private
|
34
|
-
#
|
35
|
-
# def config(conn)
|
36
|
-
# conn.add_config(:param_transformation, [:router_params])
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# def get_params(conn)
|
40
|
-
# # http://example.com/users/1/edit
|
41
|
-
# conn.params #=> { id: 1 }
|
42
|
-
# conn
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# @see WebPipe::Params
|
47
|
-
# @see https://github.com/hanami/router#string-matching-with-variables
|
9
|
+
# See the docs for the extension linked from the README.
|
48
10
|
module RouterParams
|
49
11
|
ROUTER_PARAM_KEY = 'router.params'
|
50
12
|
|
@@ -4,32 +4,9 @@ require 'web_pipe/conn'
|
|
4
4
|
require 'web_pipe/types'
|
5
5
|
require 'rack'
|
6
6
|
|
7
|
-
|
7
|
+
# :nodoc:
|
8
8
|
module WebPipe
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# This extension provides with helper methods to retrieve rack
|
12
|
-
# session and work with it while still being able to chain {Conn}
|
13
|
-
# method calls.
|
14
|
-
#
|
15
|
-
# It requires one of `Rack::Session` middlewares to be present.
|
16
|
-
#
|
17
|
-
# @example
|
18
|
-
# require 'web_pipe'
|
19
|
-
# require 'rack/session'
|
20
|
-
#
|
21
|
-
# WebPipe.load_extensions(:session)
|
22
|
-
#
|
23
|
-
# class MyApp
|
24
|
-
# include WebPipe
|
25
|
-
#
|
26
|
-
# use Rack::Session::Cookie, secret: 'top_secret'
|
27
|
-
#
|
28
|
-
# plug :add_session, ->(conn) { conn.add_session('foo', 'bar') }
|
29
|
-
# plug :fetch_session, ->(conn) { conn.add(:foo, conn.fetch_session('foo')) }
|
30
|
-
# plug :delete_session, ->(conn) { conn.delete_session('foo') }
|
31
|
-
# plug :clear_session, ->(conn) { conn.clear_session }
|
32
|
-
# end
|
9
|
+
# See the docs for the extension linked from the README.
|
33
10
|
module Session
|
34
11
|
# Type for session keys.
|
35
12
|
SESSION_KEY = Types::Strict::String
|
@@ -1,11 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# :nodoc:
|
4
4
|
module WebPipe
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# This methods are in fact redundant with the information already
|
8
|
-
# present in {Conn} struct but, of course, they are very useful.
|
5
|
+
# See the docs for the extension linked from the README.
|
9
6
|
module Url
|
10
7
|
# Base part of the URL.
|
11
8
|
#
|