web_pipe 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/README.md +13 -10
- 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/hanami_view.md +10 -14
- data/docs/extensions/params.md +6 -4
- data/docs/extensions/rails.md +28 -34
- 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 +1 -2
- 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/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 +7 -6
- 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 +2 -93
- data/lib/web_pipe/extensions/not_found/not_found.rb +2 -40
- data/lib/web_pipe/extensions/params/params.rb +2 -63
- data/lib/web_pipe/extensions/rails/rails.rb +2 -119
- 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 +30 -75
- 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 +17 -55
- data/lib/web_pipe/types.rb +1 -3
- data/lib/web_pipe/version.rb +1 -1
- data/lib/web_pipe.rb +77 -21
- data/web_pipe.gemspec +1 -0
- metadata +7 -6
- data/docs/recipes/dry_rb_integration.md +0 -17
- data/lib/web_pipe/dsl/dsl_context.rb +0 -85
- data/lib/web_pipe/dsl/instance_methods.rb +0 -114
@@ -1,114 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'web_pipe/types'
|
4
|
-
require 'web_pipe/conn'
|
5
|
-
require 'web_pipe/app'
|
6
|
-
require 'web_pipe/plug'
|
7
|
-
require 'web_pipe/rack_support/app_with_middlewares'
|
8
|
-
require 'web_pipe/rack_support/middleware_specification'
|
9
|
-
require 'web_pipe/conn_support/composition'
|
10
|
-
|
11
|
-
module WebPipe
|
12
|
-
module DSL
|
13
|
-
# Instance methods for the pipe.
|
14
|
-
#
|
15
|
-
# It is from here that you get the rack application you can route
|
16
|
-
# to. The initialization phase gives you the chance to inject any
|
17
|
-
# of the plugs or middlewares, while the instance you get has the
|
18
|
-
# `#call` method expected by rack.
|
19
|
-
#
|
20
|
-
# The pipe state can be accessed through the pipe class, which
|
21
|
-
# has been configured through {ClassContext}.
|
22
|
-
#
|
23
|
-
# @api private
|
24
|
-
module InstanceMethods
|
25
|
-
# No injections at all.
|
26
|
-
EMPTY_INJECTIONS = {
|
27
|
-
plugs: Types::EMPTY_HASH,
|
28
|
-
middlewares: Types::EMPTY_HASH
|
29
|
-
}.freeze
|
30
|
-
|
31
|
-
# Type for how plugs and middlewares should be injected.
|
32
|
-
Injections = Types::Strict::Hash.schema(
|
33
|
-
plugs: Plug::Injections,
|
34
|
-
middlewares: RackSupport::MiddlewareSpecification::Injections
|
35
|
-
)
|
36
|
-
|
37
|
-
# @!attribute [r] injections [Injections[]]
|
38
|
-
# Injected plugs and middlewares that allow overriding what
|
39
|
-
# has been configured.
|
40
|
-
attr_reader :injections
|
41
|
-
|
42
|
-
# @return [RackSupport::AppWithMiddlewares[]]
|
43
|
-
attr_reader :rack_app
|
44
|
-
|
45
|
-
# @return [Hash<Plug::Name[], ConnSupport::Composition::Operation[]>]
|
46
|
-
attr_reader :operations
|
47
|
-
|
48
|
-
# @return [Hash<RackSupport::MiddlewareSpecification::Name[], Array<RackSupport::Middlewares>]
|
49
|
-
attr_reader :middlewares
|
50
|
-
|
51
|
-
# rubocop:disable Metrics/AbcSize
|
52
|
-
def initialize(injects = EMPTY_INJECTIONS)
|
53
|
-
@injections = Injections[injects]
|
54
|
-
container = self.class.container
|
55
|
-
@middlewares = RackSupport::MiddlewareSpecification.inject_and_resolve(
|
56
|
-
self.class.middleware_specifications, injections[:middlewares]
|
57
|
-
)
|
58
|
-
@operations = Plug.inject_and_resolve(
|
59
|
-
self.class.plugs, injections[:plugs], container, self
|
60
|
-
)
|
61
|
-
app = App.new(operations.values)
|
62
|
-
@rack_app = RackSupport::AppWithMiddlewares.new(middlewares.values.flatten, app)
|
63
|
-
end
|
64
|
-
# rubocop:enable Metrics/AbcSize
|
65
|
-
|
66
|
-
# Expected interface for rack.
|
67
|
-
#
|
68
|
-
# @param env [Hash] Rack env
|
69
|
-
#
|
70
|
-
# @return [Array] Rack response
|
71
|
-
def call(env)
|
72
|
-
rack_app.call(env)
|
73
|
-
end
|
74
|
-
|
75
|
-
# Proc for the composition of all operations.
|
76
|
-
#
|
77
|
-
# This can be used to plug a {WebPipe} itself as an operation.
|
78
|
-
#
|
79
|
-
# @example
|
80
|
-
# class HtmlApp
|
81
|
-
# include WebPipe
|
82
|
-
#
|
83
|
-
# plug :html
|
84
|
-
#
|
85
|
-
# private
|
86
|
-
#
|
87
|
-
# def html(conn)
|
88
|
-
# conn.add_response_header('Content-Type', 'text/html')
|
89
|
-
# end
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# class App
|
93
|
-
# include WebPipe
|
94
|
-
#
|
95
|
-
# plug :html, &HtmlApp.new
|
96
|
-
# plug :body
|
97
|
-
#
|
98
|
-
# private
|
99
|
-
#
|
100
|
-
# def body(conn)
|
101
|
-
# conn.set_response_body('Hello, world!')
|
102
|
-
# end
|
103
|
-
# end
|
104
|
-
#
|
105
|
-
# @see ConnSupport::Composition
|
106
|
-
def to_proc
|
107
|
-
ConnSupport::Composition
|
108
|
-
.new(operations.values)
|
109
|
-
.method(:call)
|
110
|
-
.to_proc
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|