Class: Notifyor::Remote::Connection
- Inherits:
-
Object
- Object
- Notifyor::Remote::Connection
- Defined in:
- lib/notifyor/remote/connection.rb
Instance Method Summary collapse
- #build_redis_tunnel_connection ⇒ Object
- #build_tunnel ⇒ Object
- #growl_message(message) ⇒ Object
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #subscribe_to_redis ⇒ Object
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 15 16 17 18 |
# File 'lib/notifyor/remote/connection.rb', line 10 def initialize @ssh_host = ENV['ssh_host'] @ssh_port = ENV['ssh_port'] @ssh_user = ENV['ssh_user'] @tunnel_port = ENV['ssh_tunnel_port'] @redis_port = ENV['ssh_redis_port'] @ssh_gateway = nil @redis_tunnel_connection = nil end |
Instance Method Details
#build_redis_tunnel_connection ⇒ Object
27 28 29 30 |
# File 'lib/notifyor/remote/connection.rb', line 27 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_tunnel ⇒ Object
20 21 22 23 24 25 |
# File 'lib/notifyor/remote/connection.rb', line 20 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
41 42 43 |
# File 'lib/notifyor/remote/connection.rb', line 41 def () ::Notifyor::Growl.create_growl("Notifyor", ) unless Notifyor::Util::Formatter.squish!().empty? end |
#subscribe_to_redis ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/notifyor/remote/connection.rb', line 32 def subscribe_to_redis @redis_tunnel_connection.subscribe('notifyor') do |on| on. do |channel, msg| data = ::JSON.parse(msg) (data['message']) end end end |