Class: Faraday::RackBuilder

### Home Classes Methods

### In Files

- lib/faraday/rack_builder.rb

### Parent

Object

### Namespace

- CLASS Faraday::RackBuilder::Handler
- CLASS Faraday::RackBuilder::StackLocked

### Methods

- ::new
- #==
- #[]
- #adapter
- #app
- #build
- #build_env
- #build_response
- #delete
- #dup
- #insert
- #insert_after
- #insert_before
- #lock!
- #locked?
- #request
- #response
- #swap
- #to_app
- #use

### Class/Module Index

Quicksearch

- Faraday
- Faraday::Adapter
- Faraday::Adapter::EMHttp
- Faraday::Adapter::EMHttp::Manager
- Faraday::Adapter::EMHttp::Options
- Faraday::Adapter::EMSynchrony
- Faraday::Adapter::EMSynchrony::ParallelManager
- Faraday::Adapter::Excon
- Faraday::Adapter::HTTPClient
- Faraday::Adapter::NetHttp
- Faraday::Adapter::NetHttpPersistent
- Faraday::Adapter::Parallelism
- Faraday::Adapter::Patron
- Faraday::Adapter::Rack
- Faraday::Adapter::Test
- Faraday::Adapter::Test::Stub
- Faraday::Adapter::Test::Stubs
- Faraday::Adapter::Test::Stubs::NotFound
- Faraday::Adapter::Typhoeus
- Faraday::AutoloadHelper
- Faraday::ClientError
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::ConnectionFailed
- Faraday::ConnectionOptions
- Faraday::Env
- Faraday::Error
- Faraday::FlatParamsEncoder
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::MissingDependency
- Faraday::NestedParamsEncoder
- Faraday::Options
- Faraday::ParsingError
- Faraday::ProxyOptions
- Faraday::RackBuilder
- Faraday::RackBuilder::Handler
- Faraday::RackBuilder::StackLocked
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Instrumentation
- Faraday::Request::Instrumentation::Options
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::Retry::Options
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::RequestOptions
- Faraday::ResourceNotFound
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::SSLError
- Faraday::SSLOptions
- Faraday::TimeoutError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- EmHttpSslPatch
- Object

No matching classes.

# Faraday::RackBuilder

A Builder that processes requests into responses by passing through an inner middleware stack (heavily inspired by Rack).

    Faraday::Connection.new(:url => 'http://sushi.com') do |builder|
      builder.request  :url_encoded  # Faraday::Request::UrlEncoded
      builder.adapter  :net_http     # Faraday::Adapter::NetHttp
    end

### Attributes

handlers[RW]

### Public Class Methods

new(handlers = []) click to toggle source

    # File lib/faraday/rack_builder.rb, line 52
    def initialize(handlers = [])
      @handlers = handlers
      if block_given?
        build(&Proc.new)
      elsif @handlers.empty?
        # default stack, if nothing else is configured
        self.request :url_encoded
        self.adapter Faraday.default_adapter
      end
    end

### Public Instance Methods

==(other) click to toggle source

    # File lib/faraday/rack_builder.rb, line 165
    def ==(other)
      other.is_a?(self.class) && @handlers == other.handlers
    end

[](idx) click to toggle source

    # File lib/faraday/rack_builder.rb, line 69
    def [](idx)
      @handlers[idx]
    end

adapter(key, *args, &block) click to toggle source

    # File lib/faraday/rack_builder.rb, line 99
    def adapter(key, *args, &block)
      use_symbol(Faraday::Adapter, key, *args, &block)
    end

app() click to toggle source

The "rack app" wrapped in middleware. All requests are sent here.

The builder is responsible for creating the app object. After this, the builder gets locked to ensure no further modifications are made to the middleware stack.

Returns an object that responds to `call` and returns a Response.

    # File lib/faraday/rack_builder.rb, line 149
    def app
      @app ||= begin
        lock!
        to_app(lambda { |env|
          response = Response.new
          response.finish(env) unless env.parallel?
          env.response = response
        })
      end
    end

build(options = {}) click to toggle source

    # File lib/faraday/rack_builder.rb, line 63
    def build(options = {})
      raise_if_locked
      @handlers.clear unless options[:keep]
      yield(self) if block_given?
    end

build_env(connection, request) click to toggle source

ENV Keys :method - a symbolized request method (:get, :post) :body - the request body that will eventually be converted to a string. :url - URI instance for the current request. :status - HTTP response status code :request_headers - hash of HTTP Headers to be sent to the server :response_headers - Hash of HTTP headers from the server :parallel_manager - sent if the connection is in parallel mode :request - Hash of options for configuring the request.

    :timeout      - open/read timeout Integer in seconds
    :open_timeout - read timeout Integer in seconds
    :proxy        - Hash of proxy options
      :uri        - Proxy Server URI
      :user       - Proxy server username
      :password   - Proxy server password

:ssl - Hash of options for configuring SSL requests.

    # File lib/faraday/rack_builder.rb, line 189
    def build_env(connection, request)
      Env.new(request.method, request.body,
        connection.build_exclusive_url(request.path, request.params),
        request.options, request.headers, connection.ssl,
        connection.parallel_manager)
    end

build_response(connection, request) click to toggle source

Processes a Request into a Response by passing it through this Builder's middleware stack.

connection - Faraday::Connection request - Faraday::Request

Returns a Faraday::Response.

    # File lib/faraday/rack_builder.rb, line 138
    def build_response(connection, request)
      app.call(build_env(connection, request))
    end

delete(handler) click to toggle source

    # File lib/faraday/rack_builder.rb, line 126
    def delete(handler)
      raise_if_locked
      @handlers.delete(handler)
    end

dup() click to toggle source

    # File lib/faraday/rack_builder.rb, line 169
    def dup
      self.class.new(@handlers.dup)
    end

insert(index, *args, &block) click to toggle source

methods to push onto the various positions in the stack:

    # File lib/faraday/rack_builder.rb, line 105
    def insert(index, *args, &block)
      raise_if_locked
      index = assert_index(index)
      handler = self.class::Handler.new(*args, &block)
      @handlers.insert(index, handler)
    end

Also aliased as: insert_before
insert_after(index, *args, &block) click to toggle source

    # File lib/faraday/rack_builder.rb, line 114
    def insert_after(index, *args, &block)
      index = assert_index(index)
      insert(index + 1, *args, &block)
    end

insert_before(index, *args, &block) click to toggle source
Alias for: insert
lock!() click to toggle source

Locks the middleware stack to ensure no further modifications are possible.

    # File lib/faraday/rack_builder.rb, line 74
    def lock!
      @handlers.freeze
    end

locked?() click to toggle source

    # File lib/faraday/rack_builder.rb, line 78
    def locked?
      @handlers.frozen?
    end

request(key, *args, &block) click to toggle source

    # File lib/faraday/rack_builder.rb, line 91
    def request(key, *args, &block)
      use_symbol(Faraday::Request, key, *args, &block)
    end

response(key, *args, &block) click to toggle source

    # File lib/faraday/rack_builder.rb, line 95
    def response(key, *args, &block)
      use_symbol(Faraday::Response, key, *args, &block)
    end

swap(index, *args, &block) click to toggle source

    # File lib/faraday/rack_builder.rb, line 119
    def swap(index, *args, &block)
      raise_if_locked
      index = assert_index(index)
      @handlers.delete_at(index)
      insert(index, *args, &block)
    end

to_app(inner_app) click to toggle source

    # File lib/faraday/rack_builder.rb, line 160
    def to_app(inner_app)
      # last added handler is the deepest and thus closest to the inner app
      @handlers.reverse.inject(inner_app) { |app, handler| handler.build(app) }
    end

use(klass, *args, &block) click to toggle source

    # File lib/faraday/rack_builder.rb, line 82
    def use(klass, *args, &block)
      if klass.is_a? Symbol
        use_symbol(Faraday::Middleware, klass, *args, &block)
      else
        raise_if_locked
        @handlers << self.class::Handler.new(klass, *args, &block)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.