Class: Faraday::Builder

### Home Classes Methods

### In Files

- lib/faraday/builder.rb

### Parent

Object

### Namespace

- CLASS Faraday::Builder::Handler
- CLASS Faraday::Builder::StackLocked

### Methods

- ::new
- #==
- #[]
- #adapter
- #build
- #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::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::Builder
- Faraday::Builder::Handler
- Faraday::Builder::StackLocked
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::Error
- Faraday::Error::ClientError
- Faraday::Error::ConnectionFailed
- Faraday::Error::MissingDependency
- Faraday::Error::ParsingError
- Faraday::Error::ResourceNotFound
- Faraday::Error::TimeoutError
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- Object

No matching classes.

# Faraday::Builder

Possibly going to extend this a bit.

Faraday::Connection.new(:url => '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/builder.rb, line 47
    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/builder.rb, line 68
    def ==(other)
      other.is_a?(self.class) && @handlers == other.handlers
    end

[](idx) click to toggle source

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

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

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

build(options = {}) click to toggle source

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

delete(handler) click to toggle source

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

dup() click to toggle source

    # File lib/faraday/builder.rb, line 72
    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/builder.rb, line 113
    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/builder.rb, line 122
    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/builder.rb, line 82
    def lock!
      @handlers.freeze
    end

locked?() click to toggle source

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

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

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

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

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

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

    # File lib/faraday/builder.rb, line 127
    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/builder.rb, line 76
    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/builder.rb, line 90
    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.