celluloid_pubsub 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84fed17bb7b7f680cc92ad2900ca83c309eedfab
4
- data.tar.gz: 32d11a27090ea768554e42339585231511be8ea7
3
+ metadata.gz: 0f998246dbe87fcedc0e697fd863dc8cb4c0a905
4
+ data.tar.gz: 04834e2e23f0cb946992bcd7bf76133a448c69bf
5
5
  SHA512:
6
- metadata.gz: 0cd3969ed8cf6d4818a6031176915341115cf30331fce14831f6a97ec7c54de9cac529baf4733a75b0c15cb21c7aaab8701133170ad9ff496d00f5c3499d3901
7
- data.tar.gz: cd352a6d4adbd6e170d454f907b3c329e4fc695ab3093b1d647083df6698b2df96aa9938cf915a7141fee5ddc7c87521e925cd44ab5b76c6da65a88433b84d90
6
+ metadata.gz: 04af564aa19cba0cfb5cd6591d23825c7e44ce63e2f7e22a0f1bfddce2c6dbbc3aef28b144bd1c625c35e321e77b24c3d21b89fbc234fa8506f6f2cd46e2394f
7
+ data.tar.gz: 51ef6c1817146611d0bf047747d95f5acbc252217ad4886fa149f8e22d21dc58f36da2ac52f8b541a5c1e5d12bea0abe06f4ab82d9e32233c219116ccbbe2d23
data/.rubocop.yml CHANGED
@@ -3,12 +3,12 @@ AllCops:
3
3
  - washout_builder.gemspec
4
4
  - bin/**/*
5
5
  - Guardfile
6
- - vendor/**/*
7
- - examples/**/*
6
+ - vendor/**/**
7
+ - examples/**/**
8
8
 
9
9
  ClassLength:
10
10
  Max: 500
11
-
11
+
12
12
  Documentation:
13
13
  Enabled: true
14
14
 
data/README.md CHANGED
@@ -8,6 +8,8 @@ Description
8
8
 
9
9
  CelluloidPubsub is a simple ruby implementation of publish subscribe design patterns using celluloid actors and websockets, using Celluloid::Reel server
10
10
 
11
+ Starting with version 0.7.0, Support for Celluloid 0.17 has been added.
12
+
11
13
  Starting with version 0.6.0, Redis support was moved into gem [celluloid_pubsub_redis_adapter](https://github.com/bogdanRada/celluloid_pubsub_redis_adapter)
12
14
 
13
15
  Requirements
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.test_files = s.files.grep(/^(spec)/)
17
17
  s.require_paths = ['lib']
18
18
 
19
- s.add_runtime_dependency 'celluloid', '~> 0.16', '~> 0.16.0' # TODO: upgrade to version 0.17 - work in progress
20
- s.add_runtime_dependency 'celluloid-io', '~> 0.16', '>= 0.16.2'
19
+ s.add_runtime_dependency 'celluloid', '>= 0.16', '>= 0.16.0'
20
+ s.add_runtime_dependency 'celluloid-io', '>= 0.16', '>= 0.16.2'
21
21
  s.add_runtime_dependency 'reel', '~> 0.6', '>= 0.6.0'
22
22
  s.add_runtime_dependency 'http', '~> 1.0', '>= 1.0.2'
23
23
  s.add_runtime_dependency 'celluloid-websocket-client', '~> 0.0', '>= 0.0.1'
@@ -8,7 +8,6 @@ log_file_path = File.join(File.expand_path(File.dirname(__FILE__)), 'log', 'cell
8
8
  # actor that subscribes to a channel
9
9
  class FirstActor
10
10
  include Celluloid
11
- include Celluloid::Logger
12
11
 
13
12
  def initialize(options = {})
14
13
  @client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel' }.merge(options))
@@ -34,7 +33,6 @@ end
34
33
  # actor that publishes a message in a channel
35
34
  class SecondActor
36
35
  include Celluloid
37
- include Celluloid::Logger
38
36
 
39
37
  def initialize(options = {})
40
38
  @client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel2' }.merge(options))
@@ -57,9 +55,12 @@ class SecondActor
57
55
  end
58
56
 
59
57
 
60
- CelluloidPubsub::WebServer.supervise_as(:web_server, enable_debug: debug_enabled, adapter: nil,log_file_path: log_file_path )
61
- FirstActor.supervise_as(:first_actor, enable_debug: debug_enabled)
62
- SecondActor.supervise_as(:second_actor, enable_debug: debug_enabled)
58
+ # please don't use the BaseActor class to supervise actors. This is subject to change . This class is used only to test backward compatibility.
59
+ # For more information on how to supervise actors please see Celluloid wiki.
60
+ CelluloidPubsub::BaseActor.setup_actor_supervision(CelluloidPubsub::WebServer, actor_name: :web_server, args: {enable_debug: debug_enabled, adapter: nil,log_file_path: log_file_path })
61
+ CelluloidPubsub::BaseActor.setup_actor_supervision(FirstActor, actor_name: :first_actor, args: {enable_debug: debug_enabled })
62
+ CelluloidPubsub::BaseActor.setup_actor_supervision(SecondActor, actor_name: :second_actor, args: {enable_debug: debug_enabled })
63
+
63
64
  signal_received = false
64
65
 
65
66
  Signal.trap('INT') do
@@ -0,0 +1,55 @@
1
+ require_relative './helper'
2
+ module CelluloidPubsub
3
+ # base actor used for compatibility between celluloid versions
4
+ module BaseActor
5
+
6
+ class << self
7
+ include Helper
8
+ attr_reader :config
9
+
10
+ def included(base)
11
+ base.include Celluloid
12
+ base.include Celluloid::IO
13
+ base.include CelluloidPubsub::Helper
14
+ base.include config['logger_class']
15
+ end
16
+
17
+ def config
18
+ {
19
+ 'logger_class' => celluloid_logger_class
20
+ }
21
+ end
22
+
23
+ def celluloid_logger_class
24
+ if version_less_than_seventeen?
25
+ Celluloid::Logger
26
+ else
27
+ Celluloid::Internals::Logger
28
+ end
29
+ end
30
+
31
+ def celluloid_version
32
+ find_loaded_gem_property('celluloid', 'version')
33
+ end
34
+
35
+ def version_less_than_seventeen?
36
+ verify_gem_version('celluloid', '0.17', operator: '<')
37
+ end
38
+
39
+ def setup_actor_supervision(class_name, options)
40
+ if version_less_than_seventeen?
41
+ class_name.supervise_as(options[:actor_name], options[:args])
42
+ else
43
+ class_name.supervise(as: options[:actor_name], args: [options[:args]])
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
51
+ if CelluloidPubsub::BaseActor.version_less_than_seventeen?
52
+ require 'celluloid/autostart'
53
+ else
54
+ require 'celluloid/current'
55
+ end
@@ -13,9 +13,8 @@ module CelluloidPubsub
13
13
  # @!attribute channel
14
14
  # @return [String] The channel to which the client will subscribe to
15
15
  class Client
16
- include Celluloid
17
- include Celluloid::Logger
18
- include CelluloidPubsub::Helper
16
+ include CelluloidPubsub::BaseActor
17
+
19
18
 
20
19
  attr_accessor :actor, :options, :channel
21
20
  finalizer :shutdown
@@ -12,7 +12,36 @@ module CelluloidPubsub
12
12
  message.is_a?(Hash) && message['client_action'] == 'successful_subscription'
13
13
  end
14
14
 
15
- module_function
15
+ module_function
16
+
17
+ def find_loaded_gem(name, property = nil)
18
+ gem_spec = Gem.loaded_specs.values.find { |repo| repo.name == name }
19
+ gem_spec.present? && property.present? ? gem_spec.send(property) : gem_spec
20
+ end
21
+
22
+ def find_loaded_gem_property(gem_name, property = 'version')
23
+ find_loaded_gem(gem_name, property)
24
+ end
25
+
26
+ def fetch_gem_version(gem_name)
27
+ version = find_loaded_gem_property(gem_name)
28
+ version.blank? ? nil : get_parsed_version(version)
29
+ end
30
+
31
+ def get_parsed_version(version)
32
+ return 0 if version.blank?
33
+ version = version.to_s.split('.')
34
+ if version.size > 2
35
+ version.pop until version.size == 2
36
+ end
37
+ version.join('.').to_f
38
+ end
39
+
40
+ def verify_gem_version(gem_version, version, options = {})
41
+ options.stringify_keys!
42
+ version = get_parsed_version(version)
43
+ get_parsed_version(gem_version).send(options.fetch('operator', '<='), version)
44
+ end
16
45
 
17
46
  # method used to determine if a action is a subsribe action
18
47
  # @param [string] action The action that will be checked
@@ -12,11 +12,8 @@ module CelluloidPubsub
12
12
  #
13
13
  # @!attribute channels
14
14
  # @return [Array] array of channels to which the current reactor has subscribed to
15
- class Reactor
16
- include Celluloid
17
- include Celluloid::IO
18
- include Celluloid::Logger
19
- include CelluloidPubsub::Helper
15
+ class Reactor
16
+ include CelluloidPubsub::BaseActor
20
17
 
21
18
  attr_accessor :websocket, :server, :channels
22
19
  finalizer :shutdown
@@ -15,9 +15,9 @@ module CelluloidPubsub
15
15
  # major release version
16
16
  MAJOR = 0
17
17
  # minor release version
18
- MINOR = 6
18
+ MINOR = 7
19
19
  # tiny release version
20
- TINY = 1
20
+ TINY = 0
21
21
  # prelease version ( set this only if it is a prelease)
22
22
  PRE = nil
23
23
 
@@ -14,8 +14,7 @@ module CelluloidPubsub
14
14
  # @!attribute subscribers
15
15
  # @return [Hash] The hostname on which the webserver runs on
16
16
  class WebServer < Reel::Server::HTTP
17
- include Celluloid::Logger
18
- include CelluloidPubsub::Helper
17
+ include CelluloidPubsub::BaseActor
19
18
 
20
19
  # The hostname on which the webserver runs on by default
21
20
  HOST = '0.0.0.0'
@@ -1,8 +1,11 @@
1
- require 'celluloid'
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'bundler/setup'
2
4
  require 'celluloid/io'
3
5
  require 'reel'
4
6
  require 'celluloid/websocket/client'
5
7
  require 'active_support/all'
6
8
  require 'json'
9
+ require 'celluloid_pubsub/base_actor'
7
10
  Gem.find_files('celluloid_pubsub/initializers/**/*.rb').each { |path| require path }
8
11
  Gem.find_files('celluloid_pubsub/**/*.rb').each { |path| require path }
data/spec/spec_helper.rb CHANGED
@@ -44,3 +44,11 @@ RSpec.configure do |config|
44
44
  end
45
45
  end
46
46
  end
47
+
48
+
49
+ # class used for testing actions
50
+ class TestActor
51
+ include CelluloidPubsub::BaseActor
52
+ end
53
+
54
+ CelluloidPubsub::BaseActor.setup_actor_supervision(TestActor, actor_name: :test_actor, args: { })
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.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
@@ -14,27 +14,27 @@ dependencies:
14
14
  name: celluloid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.16'
20
- - - "~>"
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.16.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0.16'
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.16.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: celluloid-io
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.16'
40
40
  - - ">="
@@ -44,7 +44,7 @@ dependencies:
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0.16'
50
50
  - - ">="
@@ -368,6 +368,7 @@ files:
368
368
  - examples/simple_test.rb
369
369
  - init.rb
370
370
  - lib/celluloid_pubsub.rb
371
+ - lib/celluloid_pubsub/base_actor.rb
371
372
  - lib/celluloid_pubsub/client.rb
372
373
  - lib/celluloid_pubsub/helper.rb
373
374
  - lib/celluloid_pubsub/initializers/reel_colors.rb