Class: Evil::Client::Middleware
- Inherits:
-
Object
- Object
- Evil::Client::Middleware
- Defined in:
- lib/evil/client/middleware.rb,
lib/evil/client/middleware/merge_security.rb,
lib/evil/client/middleware/stringify_form.rb,
lib/evil/client/middleware/stringify_json.rb,
lib/evil/client/middleware/stringify_query.rb,
lib/evil/client/middleware/normalize_headers.rb,
lib/evil/client/middleware/stringify_multipart.rb
Overview
Builds and carries stack of middleware parameterized by settings
Defined Under Namespace
Classes: Base, MergeSecurity, NormalizeHeaders, StringifyForm, StringifyJson, StringifyMultipart, StringifyQuery
Class Method Summary collapse
-
.append ⇒ Object
Middleware to be added on bottom of full stack (between custom stack and connection).
-
.prepend ⇒ Object
Middleware to be added on top of full stack (before custom ones).
Instance Method Summary collapse
-
#call(other) ⇒ #call
Wraps the connection instance to the current stack of middleware.
-
#finalize(settings = nil) ⇒ self
Applies client settings to build stack of middleware.
Class Method Details
.append ⇒ Object
Middleware to be added on bottom of full stack (between custom stack and connection)
37 38 39 40 41 42 43 44 |
# File 'lib/evil/client/middleware.rb', line 37 def append new do run StringifyQuery run StringifyJson run StringifyForm run StringifyMultipart end.finalize end |
.prepend ⇒ Object
Middleware to be added on top of full stack (before custom ones)
28 29 30 31 32 33 |
# File 'lib/evil/client/middleware.rb', line 28 def prepend new do run NormalizeHeaders run MergeSecurity end.finalize end |
Instance Method Details
#call(other) ⇒ #call
Wraps the connection instance to the current stack of middleware
65 66 67 |
# File 'lib/evil/client/middleware.rb', line 65 def call(other) @stack.reverse.inject(other) { |a, e| e.new(a) } end |
#finalize(settings = nil) ⇒ self
Applies client settings to build stack of middleware
52 53 54 55 56 57 58 |
# File 'lib/evil/client/middleware.rb', line 52 def finalize(settings = nil) @mutex.synchronize do @stack = [] instance_exec(settings, &@block) if @block self end end |