Class: Notifyor::Remote::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/notifyor/remote/connection.rb

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



10
11
12
13
14
15
16
17
18
19
# File 'lib/notifyor/remote/connection.rb', line 10

def initialize
  @ssh_host = ENV['ssh_host'] || 'localhost'
  @ssh_port = ENV['ssh_port'] || '22'
  @ssh_user = ENV['ssh_user']
  @tunnel_port = ENV['ssh_tunnel_port'] || '2000'
  @redis_port = ENV['ssh_redis_port'] || '6379'
  @redis_channel = ENV['channel'] || 'notifyor'
  @ssh_gateway = nil
  @redis_tunnel_connection = nil
end

Instance Method Details

#build_redis_tunnel_connectionObject



28
29
30
31
# File 'lib/notifyor/remote/connection.rb', line 28

def build_redis_tunnel_connection
  redis_port = (['127.0.0.1', 'localhost'].include? @ssh_host) ? @redis_port : @tunnel_port
  @redis_tunnel_connection = Redis.new(port: redis_port)
end

#build_tunnelObject



21
22
23
24
25
26
# File 'lib/notifyor/remote/connection.rb', line 21

def build_tunnel
  unless ['127.0.0.1', 'localhost'].include? @ssh_host
    @ssh_gateway = Net::SSH::Gateway.new(@ssh_host, @ssh_user, port: @ssh_port)
    @ssh_gateway.open('127.0.0.1', @redis_port, @tunnel_port)
  end
end

#growl_message(message) ⇒ Object



42
43
44
# File 'lib/notifyor/remote/connection.rb', line 42

def growl_message(message)
  ::Notifyor::Growl.create_growl("Notifyor", message) unless Notifyor::Util::Formatter.squish!(message).empty?
end

#subscribe_to_redisObject



33
34
35
36
37
38
39
40
# File 'lib/notifyor/remote/connection.rb', line 33

def subscribe_to_redis
  @redis_tunnel_connection.subscribe(@redis_channel) do |on|
    on.message do |channel, msg|
      STDERR.write "INFO - Message received on channel: #{channel} \n"
      growl_message(msg)
    end
  end
end