Class: Alice::Middleware

Inherits:
Object show all
Includes:
Rack::Utils
Defined in:
lib/alice/middleware.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_errorObject

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_requestsObject 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

Returns:

  • (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(options = {})
  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