celluloid_pubsub 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfd94f2ae6742d88a6847c707e244a04c79d225a
4
- data.tar.gz: d23c662ad9624501050fd26bd2090838d05e7c29
3
+ metadata.gz: 3cadbce82ae6b66ea77ba768fe90ec8fbc761bb1
4
+ data.tar.gz: ac2d82051f17463fe80dc83950dede59c4e38efa
5
5
  SHA512:
6
- metadata.gz: 48c469b58c12d9b646eae41b1e441e965f139b49bea1789c10f1472eb22ca05ab3ce8af69e3f9fc63c7bf81822a6c1899262d8078c973f88beb76e0f34277d5a
7
- data.tar.gz: 81fd191f91fae69aca22dd833208071e80541659b7675608b6a2130ea50d5f35840616b09b7d72239f7d073473807ade86cc430ae38f8483e2c75e5cb8cf2993
6
+ metadata.gz: f2b707bfc85a7abc10ec2705dbf56dfa971fb44b33616e060520cc989a48fb492062c5ec4979d0b0c07333908e3b8ea81e369c8c5eabfddbc7c43f7e3dd859a3
7
+ data.tar.gz: 547377d28faf751328c4304dad0a644fed6239d3ffcb45b083cbbc1d4005bdf395b1957b59c017255100f2a622727db153dd810627dc62b3270fac0dafeca4c5
data/README.rdoc CHANGED
@@ -17,7 +17,7 @@ CelluloidPubsub is a simple ruby implementation of publish subscribe design patt
17
17
  3. {Celluloid-IO >= 0.16.2}[https://github.com/celluloid/celluloid-io]
18
18
  4. {Reel >= 0.5.0}[https://github.com/celluloid/reel]
19
19
  5. {Celluloid-websocket-client = 0.0.1}[https://github.com/jeremyd/celluloid-websocket-client]
20
- 6. {ActiveSuport = 0.0.1}[https://rubygems.org/gems/activesupport]
20
+ 6. {ActiveSuport >= 4.2.0}[https://rubygems.org/gems/activesupport]
21
21
 
22
22
  = Compatibility
23
23
 
@@ -0,0 +1,38 @@
1
+ require 'bundler/setup'
2
+ require 'celluloid_pubsub'
3
+
4
+ class Subscriber
5
+ include Celluloid
6
+ include Celluloid::Logger
7
+
8
+ def initialize
9
+ CelluloidPubsub::Client.connect(actor: Actor.current) do |ws|
10
+ ws.subscribe('test_channel') # this will execute after the connection is opened
11
+ end
12
+ end
13
+
14
+ def on_message(message)
15
+ puts "got #{message.inspect}"
16
+ end
17
+
18
+ def on_close(code, reason)
19
+ puts "websocket connection closed: #{code.inspect}, #{reason.inspect}"
20
+ terminate
21
+ end
22
+ end
23
+
24
+ class Publisher
25
+ include Celluloid
26
+ include Celluloid::Logger
27
+
28
+ def initialize
29
+ CelluloidPubsub::Client.connect(actor: Actor.current) do |ws|
30
+ ws.publish('test_channel', 'data' => 'my_message') # the message needs to be a Hash
31
+ end
32
+ end
33
+ end
34
+
35
+ CelluloidPubsub::WebServer.supervise_as(:web_server)
36
+ Subscriber.supervise_as(:subscriber)
37
+ Publisher.supervise_as(:publisher)
38
+ sleep
@@ -3,14 +3,22 @@ module CelluloidPubsub
3
3
  class PubSubWorker
4
4
  include Celluloid
5
5
  include Celluloid::Logger
6
- attr_accessor :actor, :connect_blk, :cllient
6
+ attr_accessor :actor, :connect_blk, :client, :options, :hostname, :port, :path
7
7
 
8
8
  def initialize(options, &connect_blk)
9
- options = options.stringify_keys!
10
- @actor = options['actor'].present? ? options['actor'] : nil
9
+ parse_options(options)
11
10
  raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
12
11
  @connect_blk = connect_blk
13
- @client = Celluloid::WebSocket::Client.new("ws://#{CelluloidPubsub::WebServer::HOST}:#{CelluloidPubsub::WebServer::PORT}#{CelluloidPubsub::WebServer::PATH}", Actor.current)
12
+ @client = Celluloid::WebSocket::Client.new("ws://#{@hostname}:#{@port}#{@path}", Actor.current)
13
+ end
14
+
15
+ def parse_options(options)
16
+ raise 'Options is not a hash' unless options.is_a?(Hash)
17
+ @options = options.stringify_keys!
18
+ @actor = @options.fetch('actor', nil)
19
+ @hostname = @options.fetch('hostname', CelluloidPubsub::WebServer::HOST)
20
+ @port = @options.fetch('port', CelluloidPubsub::WebServer::PORT)
21
+ @path = @options.fetch('path', CelluloidPubsub::WebServer::PATH)
14
22
  end
15
23
 
16
24
  def debug_enabled?
@@ -6,7 +6,7 @@ module CelluloidPubsub # Returns the version of the currently loaded Rails as a
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 4
9
+ TINY = 5
10
10
  PRE = nil
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -17,7 +17,7 @@ module CelluloidPubsub
17
17
  end
18
18
 
19
19
  def parse_options(options)
20
- raise 'Options is not a hash or is not present ' unless options.is_a?(Hash)
20
+ raise 'Options is not a hash ' unless options.is_a?(Hash)
21
21
  @options = options.stringify_keys
22
22
  @backlog = @options.fetch(:backlog, 1024)
23
23
  @hostname = @options.fetch(:hostname, CelluloidPubsub::WebServer::HOST)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
@@ -413,6 +413,7 @@ files:
413
413
  - bin/yardstick
414
414
  - bin/yri
415
415
  - celluloid_pubsub.gemspec
416
+ - examples/simple_test.rb
416
417
  - init.rb
417
418
  - lib/celluloid_pubsub.rb
418
419
  - lib/celluloid_pubsub/client_pubsub.rb