web_pipe 0.15.1 → 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 +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
data/lib/web_pipe/plug.rb
CHANGED
@@ -5,118 +5,73 @@ require 'web_pipe/types'
|
|
5
5
|
require 'web_pipe/conn_support/composition'
|
6
6
|
|
7
7
|
module WebPipe
|
8
|
-
# A plug is a specification to resolve a callable object.
|
9
|
-
#
|
10
|
-
# It is initialized with a {Name} and a {Spec} and, on resolution
|
11
|
-
# time, is called with a {Types::Container} and an {Object} to act
|
12
|
-
# in the following fashion:
|
13
|
-
#
|
14
|
-
# - When the spec responds to `#call`, it is returned itself as the
|
15
|
-
# callable object.
|
16
|
-
# - When the spec is `nil`, then a {Proc} wrapping a method with the
|
17
|
-
# plug name in `object` is returned.
|
18
|
-
# - Otherwise, spec is taken as the key to resolve the operation
|
19
|
-
# from the `container`.
|
20
|
-
#
|
21
8
|
# @api private
|
22
9
|
class Plug < Dry::Struct
|
23
|
-
#
|
10
|
+
# Raised when the specification for an operation is invalid.
|
24
11
|
class InvalidPlugError < ArgumentError
|
25
|
-
# @param name [Any] Name for the plug that can't be resolved
|
26
12
|
def initialize(name)
|
27
13
|
super(
|
28
14
|
<<~MSG
|
29
|
-
Plug with name +#{name}+
|
30
|
-
|
31
|
-
|
15
|
+
Plug with name +#{name}+ can't be resolved. You must provide
|
16
|
+
something responding to `#call` or `#to_proc`, or a key for
|
17
|
+
something registered in the container obeying those exact
|
18
|
+
constraints. If nothing is given, it's expected to be a method
|
19
|
+
defined in the context object.
|
32
20
|
MSG
|
33
21
|
)
|
34
22
|
end
|
35
23
|
end
|
36
|
-
|
37
|
-
# Type for the name of a plug.
|
38
24
|
Name = Types::Strict::Symbol.constructor(&:to_sym)
|
39
25
|
|
40
|
-
|
41
|
-
|
42
|
-
# {Plug}.
|
43
|
-
Spec = ConnSupport::Composition::Operation |
|
26
|
+
Spec = Types.Interface(:call) |
|
27
|
+
Types.Interface(:to_proc) |
|
44
28
|
Types.Constant(nil) |
|
45
29
|
Types::Strict::String |
|
46
30
|
Types::Strict::Symbol
|
47
31
|
|
48
|
-
# Type for an instance of self.
|
49
|
-
Instance = Types.Instance(self)
|
50
|
-
|
51
|
-
# Schema expected to inject plugs.
|
52
|
-
#
|
53
|
-
# @see #inject_and_resolve
|
54
32
|
Injections = Types::Strict::Hash.map(
|
55
|
-
|
33
|
+
Name, Spec
|
56
34
|
).default(Types::EMPTY_HASH)
|
57
35
|
|
58
|
-
# @!attribute [r] name
|
59
|
-
# @return [Name[]]
|
60
36
|
attribute :name, Name
|
61
37
|
|
62
|
-
# @!attribute [r] spec
|
63
|
-
# @return [Spec[]]
|
64
38
|
attribute :spec, Spec
|
65
39
|
|
66
|
-
# Creates a new instance with given `spec` but keeping `name`.
|
67
|
-
#
|
68
|
-
# @param new_spec [Spec[]]
|
69
|
-
# @return [self]
|
70
40
|
def with(new_spec)
|
71
41
|
new(spec: new_spec)
|
72
42
|
end
|
73
43
|
|
74
|
-
#
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# @raise [InvalidPlugError] When nothing callable is resolved.
|
81
|
-
def call(container, pipe)
|
82
|
-
if spec.respond_to?(:call)
|
44
|
+
# rubocop:disable Metrics/MethodLength
|
45
|
+
# rubocop:disable Metrics/AbcSize
|
46
|
+
def call(container, context)
|
47
|
+
if spec.respond_to?(:to_proc) && !spec.is_a?(Symbol)
|
48
|
+
spec.to_proc
|
49
|
+
elsif spec.respond_to?(:call)
|
83
50
|
spec
|
84
51
|
elsif spec.nil?
|
85
|
-
|
86
|
-
elsif container[spec]
|
87
|
-
container[spec]
|
52
|
+
context.method(name)
|
53
|
+
elsif container[spec]
|
54
|
+
with(container[spec]).call(container, context)
|
88
55
|
else
|
89
56
|
raise InvalidPlugError, name
|
90
57
|
end
|
91
58
|
end
|
59
|
+
# rubocop:enable Metrics/MethodLength
|
60
|
+
# rubocop:enable Metrics/AbcSize
|
92
61
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
# @container container [Types::Container[]]
|
98
|
-
# @object [Object]
|
99
|
-
#
|
100
|
-
# @return [Hash<Name[], ConnSupport::Composition::Operation[]>]
|
101
|
-
def self.inject_and_resolve(plugs, injections, container, object)
|
102
|
-
Hash[
|
103
|
-
plugs.map do |plug|
|
104
|
-
inject_and_resolve_plug(plug, injections, container, object)
|
105
|
-
end
|
106
|
-
]
|
62
|
+
def self.inject(plugs, injections)
|
63
|
+
plugs.map do |plug|
|
64
|
+
inject_plug(plug, injections)
|
65
|
+
end
|
107
66
|
end
|
108
67
|
|
109
|
-
def self.
|
68
|
+
def self.inject_plug(plug, injections)
|
110
69
|
name = plug.name
|
111
|
-
|
112
|
-
name
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
plug
|
117
|
-
end.call(container, object)
|
118
|
-
]
|
70
|
+
if injections.key?(name)
|
71
|
+
plug.with(injections[name])
|
72
|
+
else
|
73
|
+
plug
|
74
|
+
end
|
119
75
|
end
|
120
|
-
private_class_method :inject_and_resolve_plug
|
121
76
|
end
|
122
77
|
end
|
@@ -1,43 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'web_pipe/types'
|
4
3
|
require 'web_pipe/rack_support/middleware'
|
5
4
|
require 'rack'
|
6
5
|
|
7
6
|
module WebPipe
|
8
7
|
module RackSupport
|
9
|
-
# Helper to build and call a rack application with middlewares.
|
10
|
-
#
|
11
8
|
# @api private
|
12
9
|
class AppWithMiddlewares
|
13
|
-
|
14
|
-
#
|
15
|
-
# It should be something callable accepting a rack env and
|
16
|
-
# returning a rack response.
|
17
|
-
App = Types.Interface(:call)
|
18
|
-
|
19
|
-
# @!attribute [r] rack_middlewares
|
20
|
-
# @return [Array<RackMiddleware>]
|
21
|
-
attr_reader :rack_middlewares
|
22
|
-
|
23
|
-
# @!attribute [r] app
|
24
|
-
# @return [App[]]
|
25
|
-
attr_reader :app
|
26
|
-
|
27
|
-
# @return [Rack::Builder]
|
28
|
-
attr_reader :builder
|
10
|
+
attr_reader :rack_middlewares, :app, :builder
|
29
11
|
|
30
12
|
def initialize(rack_middlewares, app)
|
31
|
-
@rack_middlewares =
|
32
|
-
@app =
|
13
|
+
@rack_middlewares = rack_middlewares
|
14
|
+
@app = app
|
33
15
|
@builder = build_rack_app(rack_middlewares, app)
|
34
16
|
end
|
35
17
|
|
36
|
-
# Calls rack application.
|
37
|
-
#
|
38
|
-
# @param env [Hash] Rack env
|
39
|
-
#
|
40
|
-
# @return [Array] Rack resonse
|
41
18
|
def call(env)
|
42
19
|
builder.call(env)
|
43
20
|
end
|
@@ -5,10 +5,10 @@ require 'dry/struct'
|
|
5
5
|
|
6
6
|
module WebPipe
|
7
7
|
module RackSupport
|
8
|
+
# Wrapper for a rack middleware.
|
9
|
+
#
|
8
10
|
# Simple data structure to represent a rack middleware class with
|
9
11
|
# its initialization options.
|
10
|
-
#
|
11
|
-
# @api private
|
12
12
|
class Middleware < Dry::Struct
|
13
13
|
# Type for a rack middleware class.
|
14
14
|
MiddlewareClass = Types.Instance(Class)
|
@@ -6,83 +6,45 @@ require 'web_pipe/types'
|
|
6
6
|
|
7
7
|
module WebPipe
|
8
8
|
module RackSupport
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# Rack middlewares can be specified in two ways:
|
12
|
-
#
|
13
|
-
# - As an array where fist element is a rack middleware class
|
14
|
-
# while the rest of elements are its initialization options.
|
15
|
-
# - A single element array where it is an instance of a class
|
16
|
-
# including {WebPipe}. This specifies all {RackSupport::Middlewares} for
|
17
|
-
# that {WebPipe}.
|
9
|
+
# @api private
|
18
10
|
class MiddlewareSpecification < Dry::Struct
|
19
|
-
# Type for the name given to a middleware.
|
20
11
|
Name = Types::Strict::Symbol.constructor(&:to_sym)
|
21
12
|
|
22
|
-
# Poor type for the specification to resolve a rack middleware.
|
23
13
|
Spec = Types::Strict::Array
|
24
14
|
|
25
|
-
# Schema expected to inject middleware specifications.
|
26
|
-
#
|
27
|
-
# @see #inject_and_resolve
|
28
15
|
Injections = Types::Strict::Hash.map(
|
29
|
-
|
16
|
+
Name, Spec
|
30
17
|
).default(Types::EMPTY_HASH)
|
31
18
|
|
32
|
-
# @!attribute [r] name
|
33
|
-
# @return [Name[]]
|
34
19
|
attribute :name, Name
|
35
20
|
|
36
|
-
# @!attribute [r] spec
|
37
|
-
# @return [Spec[]]
|
38
21
|
attribute :spec, Spec
|
39
22
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
# @return [Hash<Name[], Array<RackSupport::Middleware>]
|
46
|
-
def self.inject_and_resolve(middleware_specifications, injections)
|
47
|
-
Hash[
|
48
|
-
middleware_specifications.map do |middleware_spec|
|
49
|
-
inject_and_resolve_middleware(middleware_spec, injections)
|
50
|
-
end
|
51
|
-
]
|
23
|
+
def self.inject(middleware_specifications, injections)
|
24
|
+
middleware_specifications.map do |middleware_spec|
|
25
|
+
inject_middleware(middleware_spec, injections)
|
26
|
+
end
|
52
27
|
end
|
53
28
|
|
54
|
-
def self.
|
29
|
+
def self.inject_middleware(middleware_spec, injections)
|
55
30
|
name = middleware_spec.name
|
56
|
-
|
57
|
-
name
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
middleware_spec
|
62
|
-
end.call
|
63
|
-
]
|
31
|
+
if injections.key?(name)
|
32
|
+
middleware_spec.with(injections[name])
|
33
|
+
else
|
34
|
+
middleware_spec
|
35
|
+
end
|
64
36
|
end
|
65
|
-
private_class_method :inject_and_resolve_middleware
|
66
37
|
|
67
|
-
# Resolves {RackSupport::Middlewares} from given specification.
|
68
|
-
#
|
69
|
-
# @return [Array<RackSupport::Middleware>]
|
70
38
|
def call
|
71
|
-
|
39
|
+
klass_or_pipe = spec[0]
|
72
40
|
options = spec[1..] || Types::EMPTY_ARRAY
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
[Middleware.new(middleware: klass, options: options)]
|
41
|
+
if klass_or_pipe.respond_to?(:to_middlewares)
|
42
|
+
klass_or_pipe.to_middlewares
|
43
|
+
elsif klass_or_pipe.is_a?(Class)
|
44
|
+
[Middleware.new(middleware: klass_or_pipe, options: options)]
|
78
45
|
end
|
79
46
|
end
|
80
47
|
|
81
|
-
# Returns new instance with {#spec} replaced.
|
82
|
-
#
|
83
|
-
# @param new_spec [Spec[]]
|
84
|
-
#
|
85
|
-
# @return [MiddlewareSpecification]
|
86
48
|
def with(new_spec)
|
87
49
|
new(spec: new_spec)
|
88
50
|
end
|
data/lib/web_pipe/types.rb
CHANGED
@@ -4,11 +4,9 @@ require 'dry/types'
|
|
4
4
|
require 'dry/core/constants'
|
5
5
|
|
6
6
|
module WebPipe
|
7
|
-
# Namespace for generic
|
7
|
+
# Namespace for generic types.
|
8
8
|
module Types
|
9
9
|
include Dry.Types()
|
10
10
|
include Dry::Core::Constants
|
11
|
-
|
12
|
-
Container = Interface(:[])
|
13
11
|
end
|
14
12
|
end
|
data/lib/web_pipe/version.rb
CHANGED
data/lib/web_pipe.rb
CHANGED
@@ -1,23 +1,83 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'dry/core/extensions'
|
3
4
|
require 'web_pipe/dsl/builder'
|
4
5
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
6
|
+
# Entry-point for the DSL layer.
|
7
|
+
#
|
8
|
+
# Including this module into your class adds to it a DSL layer which makes it
|
9
|
+
# convenient to interact with an instance of {WebPipe::Pipe} transparently. It
|
10
|
+
# means that the DSL is actually an optional layer, and you can achieve
|
11
|
+
# everything by using {WebPipe::Pipe} instances.
|
12
|
+
#
|
13
|
+
# Your class gets access to {WebPipe::DSL::ClassContext::DSL_METHODS} at the
|
14
|
+
# class level, while {WebPipe::DSL::InstanceContext::PIPE_METHODS} are available
|
15
|
+
# for every instance of it. Both groups of methods are delegating to
|
16
|
+
# {WebPipe::Pipe}, so you can look there for documentation.
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# class HelloWorld
|
20
|
+
# include WebPipe
|
21
|
+
#
|
22
|
+
# use :runtime, Rack::Runtime
|
23
|
+
#
|
24
|
+
# plug :content_type do |conn|
|
25
|
+
# conn.add_response_header('Content-Type', 'plain/text')
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# plug :render do |conn|
|
29
|
+
# conn.set_response_body('Hello, World!')
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# The instance of your class is itself the final rack application. When you
|
34
|
+
# initialize it, you have the chance to inject different plugs or middlewares
|
35
|
+
# from those defined at the class level.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# HelloWorld.new(
|
39
|
+
# middlewares: {
|
40
|
+
# runtime: [Class.new do
|
41
|
+
# def initialize(app)
|
42
|
+
# @app = app
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# def call(env)
|
46
|
+
# status, headers, body = @app.call(env)
|
47
|
+
# [status, headers.merge('Injected' => '1'), body]
|
48
|
+
# end
|
49
|
+
# end]
|
50
|
+
# },
|
51
|
+
# plugs: {
|
52
|
+
# render: ->(conn) { conn.set_response_body('Injected!') }
|
53
|
+
# }
|
54
|
+
# )
|
8
55
|
module WebPipe
|
9
56
|
extend Dry::Core::Extensions
|
10
57
|
|
11
|
-
#
|
12
|
-
#
|
58
|
+
# Called via {Module#include}, makes available web_pipe's DSL.
|
59
|
+
#
|
60
|
+
# Includes an instance of `Builder`. That means that `Builder#included` is
|
61
|
+
# eventually called.
|
13
62
|
def self.included(klass)
|
14
63
|
klass.include(call)
|
15
64
|
end
|
16
65
|
|
66
|
+
# Chained to {Module#include} to make the DSL available and provide options.
|
67
|
+
#
|
68
|
+
# @param container [#[]] Container from where resolve operations. See
|
69
|
+
# {WebPipe::Plug}.
|
70
|
+
#
|
71
|
+
# @example
|
72
|
+
# include WebPipe.call(container: Container)
|
17
73
|
def self.call(**opts)
|
18
74
|
DSL::Builder.new(**opts)
|
19
75
|
end
|
20
76
|
|
77
|
+
register_extension :container do
|
78
|
+
require 'web_pipe/extensions/container/container'
|
79
|
+
end
|
80
|
+
|
21
81
|
register_extension :cookies do
|
22
82
|
require 'web_pipe/extensions/cookies/cookies'
|
23
83
|
end
|
@@ -27,24 +87,16 @@ module WebPipe
|
|
27
87
|
require 'web_pipe/extensions/dry_schema/plugs/sanitize_params'
|
28
88
|
end
|
29
89
|
|
30
|
-
register_extension :hanami_view do
|
31
|
-
require 'web_pipe/extensions/hanami_view/hanami_view'
|
32
|
-
end
|
33
|
-
|
34
|
-
register_extension :container do
|
35
|
-
require 'web_pipe/extensions/container/container'
|
36
|
-
end
|
37
|
-
|
38
90
|
register_extension :flash do
|
39
91
|
require 'web_pipe/extensions/flash/flash'
|
40
92
|
end
|
41
93
|
|
42
|
-
register_extension :
|
43
|
-
require 'web_pipe/extensions/
|
94
|
+
register_extension :hanami_view do
|
95
|
+
require 'web_pipe/extensions/hanami_view/hanami_view'
|
44
96
|
end
|
45
97
|
|
46
|
-
register_extension :
|
47
|
-
require 'web_pipe/extensions/
|
98
|
+
register_extension :not_found do
|
99
|
+
require 'web_pipe/extensions/not_found/not_found'
|
48
100
|
end
|
49
101
|
|
50
102
|
register_extension :params do
|
@@ -55,6 +107,14 @@ module WebPipe
|
|
55
107
|
require 'web_pipe/extensions/rails/rails'
|
56
108
|
end
|
57
109
|
|
110
|
+
register_extension :redirect do
|
111
|
+
require 'web_pipe/extensions/redirect/redirect'
|
112
|
+
end
|
113
|
+
|
114
|
+
register_extension :router_params do
|
115
|
+
require 'web_pipe/extensions/router_params/router_params'
|
116
|
+
end
|
117
|
+
|
58
118
|
register_extension :session do
|
59
119
|
require 'web_pipe/extensions/session/session'
|
60
120
|
end
|
@@ -62,8 +122,4 @@ module WebPipe
|
|
62
122
|
register_extension :url do
|
63
123
|
require 'web_pipe/extensions/url/url'
|
64
124
|
end
|
65
|
-
|
66
|
-
register_extension :not_found do
|
67
|
-
require 'web_pipe/extensions/not_found/not_found'
|
68
|
-
end
|
69
125
|
end
|
data/web_pipe.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = 'Rack application builder through a pipe of operations on an immutable struct.'
|
14
14
|
spec.homepage = 'https://github.com/waiting-for-dev/web_pipe'
|
15
|
+
spec.licenses = ['MIT']
|
15
16
|
|
16
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_pipe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Busqué
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|
@@ -295,7 +295,7 @@ files:
|
|
295
295
|
- docs/plugs.md
|
296
296
|
- docs/plugs/config.md
|
297
297
|
- docs/plugs/content_type.md
|
298
|
-
- docs/recipes/
|
298
|
+
- docs/recipes/hanami_2_and_dry_rb_integration.md
|
299
299
|
- docs/recipes/hanami_router_integration.md
|
300
300
|
- docs/recipes/using_all_restful_methods.md
|
301
301
|
- docs/testing.md
|
@@ -313,8 +313,7 @@ files:
|
|
313
313
|
- lib/web_pipe/conn_support/types.rb
|
314
314
|
- lib/web_pipe/dsl/builder.rb
|
315
315
|
- lib/web_pipe/dsl/class_context.rb
|
316
|
-
- lib/web_pipe/dsl/
|
317
|
-
- lib/web_pipe/dsl/instance_methods.rb
|
316
|
+
- lib/web_pipe/dsl/instance_context.rb
|
318
317
|
- lib/web_pipe/extensions/container/container.rb
|
319
318
|
- lib/web_pipe/extensions/cookies/cookies.rb
|
320
319
|
- lib/web_pipe/extensions/dry_schema/dry_schema.rb
|
@@ -329,6 +328,7 @@ files:
|
|
329
328
|
- lib/web_pipe/extensions/router_params/router_params.rb
|
330
329
|
- lib/web_pipe/extensions/session/session.rb
|
331
330
|
- lib/web_pipe/extensions/url/url.rb
|
331
|
+
- lib/web_pipe/pipe.rb
|
332
332
|
- lib/web_pipe/plug.rb
|
333
333
|
- lib/web_pipe/plugs.rb
|
334
334
|
- lib/web_pipe/plugs/config.rb
|
@@ -341,7 +341,8 @@ files:
|
|
341
341
|
- lib/web_pipe/version.rb
|
342
342
|
- web_pipe.gemspec
|
343
343
|
homepage: https://github.com/waiting-for-dev/web_pipe
|
344
|
-
licenses:
|
344
|
+
licenses:
|
345
|
+
- MIT
|
345
346
|
metadata:
|
346
347
|
allowed_push_host: https://rubygems.org
|
347
348
|
homepage_uri: https://github.com/waiting-for-dev/web_pipe
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# dry-rb integration
|
2
|
-
|
3
|
-
`web_pipe` has been designed to integrate smoothly with
|
4
|
-
[dry-rb](https://dry-rb.org/) ecosystem. It shares same design
|
5
|
-
principles and it ships with some extensions which even make this
|
6
|
-
integration tighter (like [`:dry-schema`](../extensions/dry_schema.md)
|
7
|
-
extension).
|
8
|
-
|
9
|
-
If you want to use `web_pipe` with the rest of dry-rb libraries,
|
10
|
-
your best bet is to use
|
11
|
-
[`dry-web-web_pipe`](https://github.com/waiting-for-dev/dry-web-web_pipe)
|
12
|
-
skeleton generator. It is a fork of
|
13
|
-
[`dry-web-roda`](https://github.com/dry-rb/dry-web-roda) with
|
14
|
-
`roda` dependency switched to a combination of `web_pipe` and
|
15
|
-
[`hanami-router`](https://github.com/hanami/router).
|
16
|
-
|
17
|
-
Look at `dry-web-web_pipe` README for more details.
|
@@ -1,85 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'web_pipe'
|
4
|
-
require 'web_pipe/types'
|
5
|
-
require 'web_pipe/plug'
|
6
|
-
require 'web_pipe/rack_support/middleware_specification'
|
7
|
-
|
8
|
-
module WebPipe
|
9
|
-
module DSL
|
10
|
-
# Defines the DSL for the pipe class and keeps it state.
|
11
|
-
#
|
12
|
-
# This allows adding rack middlewares and plugs at the class
|
13
|
-
# definition level.
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
class DSLContext
|
17
|
-
# @!attribute middleware_specifications
|
18
|
-
# @return [Array<RackSupport::MiddlewareSpecifications>]
|
19
|
-
attr_reader :middleware_specifications
|
20
|
-
|
21
|
-
# @!attribute plugs
|
22
|
-
# @return [Array<Plug>]
|
23
|
-
attr_reader :plugs
|
24
|
-
|
25
|
-
def initialize(middleware_specifications, plugs)
|
26
|
-
@middleware_specifications = Types.Array(
|
27
|
-
RackSupport::MiddlewareSpecification
|
28
|
-
)[middleware_specifications]
|
29
|
-
@plugs = Types.Array(Plug::Instance)[plugs]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Creates and add rack middleware specifications to the stack.
|
33
|
-
#
|
34
|
-
# The spec can be given in two forms:
|
35
|
-
#
|
36
|
-
# - As one or two arguments, first one being a
|
37
|
-
# rack middleware class and second one optionally its
|
38
|
-
# initialization options.
|
39
|
-
# - As a {WebPipe} class instance, in which case all its rack
|
40
|
-
# middlewares will be considered.
|
41
|
-
#
|
42
|
-
# @param name [RackSupport::MiddlewareSpecification::Name[]]
|
43
|
-
# @param spec [RackSupport::MiddlewareSpecification::Spec[]]
|
44
|
-
#
|
45
|
-
# @return [Array<RackSupport::Middleware>]
|
46
|
-
def use(name, *spec)
|
47
|
-
middleware_specifications << RackSupport::MiddlewareSpecification.new(name: name, spec: spec)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Creates and adds a plug to the stack.
|
51
|
-
#
|
52
|
-
# The spec can be given as a {Plug::Spec}, as a block (which
|
53
|
-
# is captured into a {Proc}, one of the options for a
|
54
|
-
# {Plug::Spec} or as a {WebPipe} (in which case all its plugs
|
55
|
-
# will be composed).
|
56
|
-
#
|
57
|
-
# @param name [Plug::Name[]]
|
58
|
-
# @param spec [Plug::Spec[], WebPipe]
|
59
|
-
# @param block_spec [Proc]
|
60
|
-
#
|
61
|
-
# @return [Array<Plug>]
|
62
|
-
def plug(name, spec = nil, &block_spec)
|
63
|
-
plug_spec = if spec.is_a?(WebPipe)
|
64
|
-
spec.to_proc
|
65
|
-
elsif spec
|
66
|
-
spec
|
67
|
-
else
|
68
|
-
block_spec
|
69
|
-
end
|
70
|
-
|
71
|
-
plugs << Plug.new(name: name, spec: plug_spec)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Adds middlewares and plugs from a WebPipe to respective
|
75
|
-
# stacks.
|
76
|
-
#
|
77
|
-
# @param name [Plug::Name[], Middleware::Name[]]
|
78
|
-
# @param spec [WebPipe]
|
79
|
-
def compose(name, spec)
|
80
|
-
use(name, spec)
|
81
|
-
plug(name, spec)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|