Class: FlyingSphinx::Tunnel

Inherits:
Object
  • Object
show all
Defined in:
lib/flying_sphinx/tunnel.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Tunnel

Returns a new instance of Tunnel.



15
16
17
# File 'lib/flying_sphinx/tunnel.rb', line 15

def initialize(configuration)
  @configuration = configuration
end

Class Method Details

.connect(configuration, &block) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/flying_sphinx/tunnel.rb', line 2

def self.connect(configuration, &block)
  tunnel = new configuration
  tunnel.open do |session|
    session.loop do
      block.call
    end
  end
end

.required?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/flying_sphinx/tunnel.rb', line 11

def self.required?
  ThinkingSphinx.database_adapter == FlyingSphinx::HerokuSharedAdapter
end

Instance Method Details

#open(&block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flying_sphinx/tunnel.rb', line 19

def open(&block)
  session = Net::SSH.start(@configuration.host, 'sphinx', ssh_options)
  session.forward.remote(
    db_port, db_host, @configuration.database_port, '0.0.0.0'
  )

  session.loop { !remote_exists?(session) }
  
  yield session
rescue IOError
  # Server closed the connection on us. That's (hopefully) expected, nothing
  # to worry about.
end