Class: Alice::Middleware
- Includes:
- Rack::Utils
- Defined in:
- lib/alice/middleware.rb
Direct Known Subclasses
Adapter::NetHttp, Adapter::Patron, Adapter::Test, Adapter::Typhoeus, Request::ActiveSupportJson, Request::Yajl, Response::Middleware
Class Attribute Summary collapse
-
.load_error ⇒ Object
Returns the value of attribute load_error.
-
.supports_parallel_requests ⇒ Object
(also: supports_parallel_requests?)
Returns the value of attribute supports_parallel_requests.
Class Method Summary collapse
- .loaded? ⇒ Boolean
-
.setup_parallel_manager(options = {}) ⇒ Object
valid parallel managers should respond to #run with no parameters.
Instance Method Summary collapse
- #create_form_params(params, base = nil) ⇒ Object
-
#full_path_for(path, query = nil, fragment = nil) ⇒ Object
assume that query and fragment are already encoded properly.
-
#initialize(app = nil) ⇒ Middleware
constructor
A new instance of Middleware.
- #process_body_for_request(env) ⇒ Object
Constructor Details
#initialize(app = nil) ⇒ Middleware
Returns a new instance of Middleware.
20 21 22 |
# File 'lib/alice/middleware.rb', line 20 def initialize(app = nil) @app = app end |
Class Attribute Details
.load_error ⇒ Object
Returns the value of attribute load_error.
6 7 8 |
# File 'lib/alice/middleware.rb', line 6 def load_error @load_error end |
.supports_parallel_requests ⇒ Object Also known as: supports_parallel_requests?
Returns the value of attribute supports_parallel_requests.
6 7 8 |
# File 'lib/alice/middleware.rb', line 6 def supports_parallel_requests @supports_parallel_requests end |
Class Method Details
.loaded? ⇒ Boolean
16 17 18 |
# File 'lib/alice/middleware.rb', line 16 def self.loaded? @load_error.nil? end |
.setup_parallel_manager(options = {}) ⇒ Object
valid parallel managers should respond to #run with no parameters. otherwise, return a short wrapper around it.
11 12 13 |
# File 'lib/alice/middleware.rb', line 11 def setup_parallel_manager( = {}) nil end |
Instance Method Details
#create_form_params(params, base = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/alice/middleware.rb', line 43 def create_form_params(params, base = nil) [].tap do |result| params.each_key do |key| key_str = base ? "#{base}[#{key}]" : key value = params[key] wee = (value.kind_of?(Hash) ? create_form_params(value, key_str) : "#{key_str}=#{escape(value.to_s)}") result << wee end end.join("&") end |
#full_path_for(path, query = nil, fragment = nil) ⇒ Object
assume that query and fragment are already encoded properly
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/alice/middleware.rb', line 25 def full_path_for(path, query = nil, fragment = nil) full_path = path.dup if query && !query.empty? full_path << "?#{query}" end if fragment && !fragment.empty? full_path << "##{fragment}" end full_path end |
#process_body_for_request(env) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/alice/middleware.rb', line 36 def process_body_for_request(env) # if it's a string, pass it through return if env[:body].nil? || env[:body].empty? || !env[:body].respond_to?(:each_key) env[:request_headers]['Content-Type'] ||= 'application/x-www-form-urlencoded' env[:body] = create_form_params(env[:body]) end |