Class: DropboxApi::MiddleWare::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/dropbox_api/middleware/stack.rb

Instance Method Summary collapse

Constructor Details

#initializeStack

Returns a new instance of Stack.


3
4
5
# File 'lib/dropbox_api/middleware/stack.rb', line 3

def initialize
  @prependable, @appendable = [], []
end

Instance Method Details

#adapter=(value) ⇒ Object


15
16
17
# File 'lib/dropbox_api/middleware/stack.rb', line 15

def adapter=(value)
  @adapter = value
end

#append(&block) ⇒ Object


11
12
13
# File 'lib/dropbox_api/middleware/stack.rb', line 11

def append(&block)
  @appendable << block
end

#apply(connection) {|connection| ... } ⇒ Object

Yields:

  • (connection)

19
20
21
22
23
24
25
26
# File 'lib/dropbox_api/middleware/stack.rb', line 19

def apply(connection)
  @prependable.each { |block| block.yield(connection) }
  yield connection
  @appendable.each { |block| block.yield(connection) }

  # Adapter must be the last middleware configured
  connection.adapter(@adapter || Faraday.default_adapter)
end

#prepend(&block) ⇒ Object


7
8
9
# File 'lib/dropbox_api/middleware/stack.rb', line 7

def prepend(&block)
  @prependable << block
end