web_pipe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ require 'dry/initializer'
2
+ require 'web_pipe/types'
3
+ require 'web_pipe/rack/middleware'
4
+ require 'rack'
5
+
6
+ module WebPipe
7
+ module Rack
8
+ # Helper to build and call a rack application with middlewares.
9
+ #
10
+ # @private
11
+ class AppWithMiddlewares
12
+ # Type for a rack application.
13
+ #
14
+ # It should be something callable accepting a rack env and
15
+ # returning a rack response.
16
+ App = Types.Contract(:call)
17
+
18
+ # @!attribute [r] rack_middlewares
19
+ # @return [Array<RackMiddleware>]
20
+
21
+ # @!attribute [r] app
22
+ # @return [App[]]
23
+
24
+
25
+ include Dry::Initializer.define -> do
26
+ param :rack_middlewares,
27
+ type: Types.Array(Middleware::Instance)
28
+
29
+ param :app, type: App
30
+ end
31
+
32
+ # @return [Rack::Builder]
33
+ attr_reader :builder
34
+
35
+ def initialize(*args)
36
+ super
37
+ @builder = build_rack_app(rack_middlewares, app)
38
+ end
39
+
40
+ # Calls rack application.
41
+ #
42
+ # @param env [Hash] Rack env
43
+ #
44
+ # @return [Array] Rack resonse
45
+ def call(env)
46
+ builder.call(env)
47
+ end
48
+
49
+ private
50
+
51
+ def build_rack_app(rack_middlewares, app)
52
+ ::Rack::Builder.new.tap do |b|
53
+ rack_middlewares.each do |middleware|
54
+ b.use(middleware.middleware, *middleware.middleware_options)
55
+ end
56
+ b.run(app)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,33 @@
1
+ require 'dry/initializer'
2
+ require 'web_pipe/types'
3
+
4
+ module WebPipe
5
+ module Rack
6
+ # Simple data structure to represent a rack middleware class with
7
+ # its initialization options.
8
+ class Middleware
9
+ # Type for an instance of self.
10
+ Instance = Types.Instance(self)
11
+
12
+ # Type for a rack middleware class.
13
+ MiddlewareClass = Types.Instance(Class)
14
+
15
+ # Type for the options to initialize a rack middleware.
16
+ Options = Types::Strict::Array
17
+
18
+ # @!attribute [r] middleware
19
+ # @return [MiddlewareClass[]] Rack middleware
20
+
21
+ # @!attribute [r] options
22
+ # @return [Options[]]
23
+ # Options to initialize the rack middleware
24
+
25
+
26
+ include Dry::Initializer.define -> do
27
+ param :middleware, type: MiddlewareClass
28
+
29
+ param :middleware_options, type: Options
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ require 'dry/types'
2
+
3
+ module WebPipe
4
+ # Namespace for generic library types.
5
+ module Types
6
+ include Dry.Types()
7
+
8
+ # Type constructor which validates value fulfills with expected
9
+ # methods.
10
+ #
11
+ # @param methods [Array<Symbols>]
12
+ #
13
+ # @return [Object] on success
14
+ # @raise Dry::Types::CoercionError when value does not respond
15
+ # to all the methods.
16
+ def self.Contract(*methods)
17
+ Constructor(Nominal::Any) do |value|
18
+ methods.reduce(value) do |value, method|
19
+ if value.respond_to?(method)
20
+ value
21
+ else
22
+ raise NoMethodError, "+#{value.inspect}+ does not respond to +#{method}+"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ # Anything which can resolve from a `#[]` method.
29
+ Container = Contract(:[])
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module WebPipe
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "web_pipe/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "web_pipe"
9
+ spec.version = WebPipe::VERSION
10
+ spec.authors = ["Marc Busqué"]
11
+ spec.email = ["marc@lamarciana.com"]
12
+
13
+ spec.summary = %q{Rack application builder through a pipe of operations on an immutable struct.}
14
+ spec.homepage = "https://github.com/waiting-for-dev/web_pipe"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["changelog_uri"] = spec.homepage + '/CHANGELOG.md'
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_runtime_dependency "rack", "~> 2.0"
39
+ spec.add_runtime_dependency "dry-monads", "~> 1.2"
40
+ spec.add_runtime_dependency "dry-types", "~> 1.0"
41
+ spec.add_runtime_dependency "dry-struct", "~> 1.0"
42
+ spec.add_runtime_dependency "dry-initializer", "~> 3.0"
43
+
44
+ spec.add_development_dependency "bundler", "~> 1.17"
45
+ spec.add_development_dependency "rake", "~> 10.0"
46
+ spec.add_development_dependency "rspec", "~> 3.0"
47
+ spec.add_development_dependency "rack-test", "~> 1.1"
48
+ spec.add_development_dependency "yard", "~> 0.9"
49
+ spec.add_development_dependency "redcarpet", "~> 3.4"
50
+ spec.add_development_dependency "pry-byebug"
51
+ end
metadata ADDED
@@ -0,0 +1,244 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web_pipe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marc Busqué
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-monads
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-struct
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dry-initializer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.17'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.17'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rack-test
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.9'
153
+ - !ruby/object:Gem::Dependency
154
+ name: redcarpet
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.4'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.4'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry-byebug
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description:
182
+ email:
183
+ - marc@lamarciana.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".travis.yml"
191
+ - ".yardopts"
192
+ - CHANGELOG.md
193
+ - Gemfile
194
+ - Gemfile.lock
195
+ - README.md
196
+ - Rakefile
197
+ - bin/console
198
+ - bin/setup
199
+ - lib/dry/monads/result/extensions/either.rb
200
+ - lib/web_pipe.rb
201
+ - lib/web_pipe/app.rb
202
+ - lib/web_pipe/conn.rb
203
+ - lib/web_pipe/conn_support/builder.rb
204
+ - lib/web_pipe/conn_support/errors.rb
205
+ - lib/web_pipe/conn_support/headers.rb
206
+ - lib/web_pipe/conn_support/types.rb
207
+ - lib/web_pipe/dsl/builder.rb
208
+ - lib/web_pipe/dsl/class_context.rb
209
+ - lib/web_pipe/dsl/dsl_context.rb
210
+ - lib/web_pipe/dsl/instance_methods.rb
211
+ - lib/web_pipe/plug.rb
212
+ - lib/web_pipe/rack/app_with_middlewares.rb
213
+ - lib/web_pipe/rack/middleware.rb
214
+ - lib/web_pipe/types.rb
215
+ - lib/web_pipe/version.rb
216
+ - web_pipe.gemspec
217
+ homepage: https://github.com/waiting-for-dev/web_pipe
218
+ licenses: []
219
+ metadata:
220
+ allowed_push_host: https://rubygems.org
221
+ homepage_uri: https://github.com/waiting-for-dev/web_pipe
222
+ source_code_uri: https://github.com/waiting-for-dev/web_pipe
223
+ changelog_uri: https://github.com/waiting-for-dev/web_pipe/CHANGELOG.md
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ requirements: []
239
+ rubyforge_project:
240
+ rubygems_version: 2.7.8
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: Rack application builder through a pipe of operations on an immutable struct.
244
+ test_files: []