Class: Net::Snarl
- Inherits:
-
Object
- Object
- Net::Snarl
- Defined in:
- lib/net/snarl.rb
Constant Summary collapse
- HEADER =
"type=SNP".freeze
- PROTOCOL_VERSION =
"version=1.0".freeze
- TERMINATOR =
"\r\n".freeze
- DEFAULT_TIMEOUT =
10
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #add_class(app, klass, params = {}) ⇒ Object
- #hello ⇒ Object
-
#initialize(host = nil, port = nil) ⇒ Snarl
constructor
A new instance of Snarl.
- #inspect ⇒ Object
- #notify(params = {}) ⇒ Object
- #register(app) ⇒ Object
- #unregister(app) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(host = nil, port = nil) ⇒ Snarl
Returns a new instance of Snarl.
12 13 14 15 |
# File 'lib/net/snarl.rb', line 12 def initialize(host = nil, port = nil) @host = host || '127.0.0.1' @port = (port || 9887).to_i end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/net/snarl.rb', line 10 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/net/snarl.rb', line 10 def port @port end |
Instance Method Details
#add_class(app, klass, params = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/net/snarl.rb', line 31 def add_class(app, klass, params = {}) params[:app] = app params[:class] = klass connected { |c| c.write command('add_class', params) } end |
#hello ⇒ Object
38 39 40 |
# File 'lib/net/snarl.rb', line 38 def hello connected { |c| c.write command('hello') } end |
#inspect ⇒ Object
46 47 48 49 |
# File 'lib/net/snarl.rb', line 46 def inspect version = hello.split('/').last "#<#{self.class} host=#{@host}, port=#{@port}, version=#{version.inspect}>" end |
#notify(params = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/net/snarl.rb', line 17 def notify(params = {}) add_defaults(params) connected { |c| c.write command('notification', params) } end |
#register(app) ⇒ Object
23 24 25 |
# File 'lib/net/snarl.rb', line 23 def register(app) connected { |c| c.write command('register', :app => app) } end |
#unregister(app) ⇒ Object
27 28 29 |
# File 'lib/net/snarl.rb', line 27 def unregister(app) connected { |c| c.write command('unregister', :app => app) } end |
#version ⇒ Object
42 43 44 |
# File 'lib/net/snarl.rb', line 42 def version connected { |c| c.write command('version') } end |