Class: Elastictastic::Middleware::Rotor::Node

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/elastictastic/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, url) ⇒ Node

Returns a new instance of Node.



99
100
101
102
103
104
105
# File 'lib/elastictastic/middleware.rb', line 99

def initialize(app, url)
  super(app)
  # Create a connection instance so we can use its #build_url method.
  # Kinda lame -- seems like it would make more sense for Faraday to
  # just implement a middleware for injecting a host/path prefix.
  @connection = Faraday::Connection.new(:url => url)
end

Instance Attribute Details

#next ⇒ Object

Returns the value of attribute next.



97
98
99
# File 'lib/elastictastic/middleware.rb', line 97

def next
  @next
end

Instance Method Details

#call(env) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/elastictastic/middleware.rb', line 107

def call(env)
  original_url = env[:url]
  begin
    env[:url] = @connection.build_url(original_url)
    @app.call(env)
  ensure
    env[:url] = original_url
  end
end