Sha256: d2a8754687903663f77fb5df104a784ad7ab34a9c40bd4af97a37d1204da26f8
Contents?: true
Size: 1.46 KB
Versions: 3
Compression:
Stored size: 1.46 KB
Contents
require 'redis-objects' require 'notifyor' require 'notifyor/growl' require 'notifyor/util/formatter' require 'notifyor/errors/ssh_error' require 'net/ssh/gateway' module Notifyor module Remote class Connection def initialize @ssh_host = ::Notifyor.configuration.ssh_host @ssh_port = ::Notifyor.configuration.ssh_port @ssh_user = ::Notifyor.configuration.ssh_user @tunnel_port = ::Notifyor.configuration.tunnel_port @redis_port = ::Notifyor.configuration.redis_port @ssh_gateway = nil @redis_tunnel_connection = nil end 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 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 def subscribe_to_redis @redis_tunnel_connection.subscribe('notifyor') do |on| on.message do |channel, msg| data = JSON.parse(msg) growl_message(data['message']) end end end def growl_message(message) ::Notifyor::Growl.create_growl("Notifyor", message) unless Notifyor::Util::Formatter.squish!(message).empty? end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
notifyor-0.5.2 | lib/notifyor/remote/connection.rb |
notifyor-0.5.1 | lib/notifyor/remote/connection.rb |
notifyor-0.5.0 | lib/notifyor/remote/connection.rb |