wisper-celluloid 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eec774f27f6a9f9f69891d93610cd765ded94119
4
+ data.tar.gz: 1e2e9b79a409b44eb27a2ba9cee095ea2bfb0eea
5
+ SHA512:
6
+ metadata.gz: 3d27385e6c1ef0223829a501707bf9ec00d1e4e1bbc409e85309b6e5631fc0e76d9bd0c816fee0232e46671f940cbe5af222afe895524e763f20fe6d0c02c035
7
+ data.tar.gz: 0ff689bfeb18c7b9d726156352b9cfd704b380b03eacf8777c572eef8bce55d2de876d899adefcce03f5754012515512791bdfa6e20808d3d2ce66b3e98cfbb7
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ script: rspec spec
3
+ rvm:
4
+ - '1.9.3'
5
+ - '2.0.0'
6
+ - '2.1.2'
7
+ - jruby
8
+ - rbx-2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'coveralls', require: false
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kris Leech
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Wisper::Celluloid
2
+
3
+ Provides [Wisper](https://github.com/krisleech/wisper) with asynchronous event
4
+ publishing using [Celluloid](https://github.com/celluloid/celluloid) actors.
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/wisper-celluloid.png)](http://badge.fury.io/rb/wisper-celluloid)
7
+ [![Code Climate](https://codeclimate.com/github/krisleech/wisper-celluloid.png)](https://codeclimate.com/github/krisleech/wisper-celluloid)
8
+ [![Build Status](https://travis-ci.org/krisleech/wisper-celluloid.png?branch=master)](https://travis-ci.org/krisleech/wisper-celluloid)
9
+ [![Coverage Status](https://coveralls.io/repos/krisleech/wisper-celluloid/badge.png?branch=master)](https://coveralls.io/r/krisleech/wisper-celluloid?branch=master)
10
+
11
+ ## Installation
12
+
13
+ ```ruby
14
+ gem 'wisper-celluloid'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ my_publisher.subscribe(MyListener.new, async: true)
21
+ ```
22
+
23
+ The listener is transparently turned in to a Celluloid Actor.
24
+
25
+ Please refer to [Celluloid](https://github.com/celluloid/celluloid/wiki)
26
+ for more information, particularly the
27
+ [Gotchas](https://github.com/celluloid/celluloid/wiki/Gotchas).
28
+
29
+ ## Compatibility
30
+
31
+ Tested with 1.9.3, 2.x, JRuby and Rubinius.
32
+ See the [build status](https://travis-ci.org/krisleech/wisper-async) for details.
33
+
34
+ ## Contributing
35
+
36
+ Yes please, either submit a PR or open an issue first to discuss your thoughts.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ require "wisper"
2
+ require "wisper/celluloid_broadcaster"
3
+ require "wisper/celluloid/version"
@@ -0,0 +1,5 @@
1
+ module Wisper
2
+ module Celluloid
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require 'celluloid/autostart'
2
+
3
+ module Wisper
4
+ class CelluloidBroadcaster
5
+ def broadcast(subscriber, publisher, event, args)
6
+ Wrapper.new(subscriber).async.broadcast(event, args)
7
+ end
8
+
9
+ class Wrapper
10
+ include ::Celluloid
11
+
12
+ def initialize(subscriber)
13
+ @subscriber = subscriber
14
+ end
15
+
16
+ def broadcast(event, args)
17
+ @subscriber.public_send(event, *args)
18
+ terminate
19
+ end
20
+ end
21
+
22
+ def self.register
23
+ Wisper.configure do |config|
24
+ config.broadcaster :celluloid, CelluloidBroadcaster.new
25
+ config.broadcaster :async, CelluloidBroadcaster.new
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Wisper::CelluloidBroadcaster.register
@@ -0,0 +1,71 @@
1
+ module Wisper
2
+ describe CelluloidBroadcaster do
3
+ FILE_PATH = Pathname(File.dirname(__FILE__)).join('test_file')
4
+ SLEEP_FOR = 2
5
+
6
+ after do
7
+ system("rm #{FILE_PATH}") if File.exist?(FILE_PATH)
8
+ end
9
+
10
+ let(:publisher) { MyPublisher.new }
11
+
12
+ class MyPublisher
13
+ include Wisper::Publisher
14
+
15
+ def ping
16
+ broadcast(:pong)
17
+ end
18
+ end
19
+
20
+ class MyListener
21
+ def pong
22
+ touch_file
23
+ sleep(SLEEP_FOR)
24
+ end
25
+
26
+ private
27
+
28
+ def touch_file
29
+ File.open(FILE_PATH, 'w') { |file| file.write(Thread.current.object_id) }
30
+ end
31
+ end
32
+
33
+ # for sanity...
34
+ describe 'without CelluloidBroadcaster' do
35
+ it "takes longer than #{SLEEP_FOR} seconds" do
36
+ publisher.add_listener(MyListener.new)
37
+ duration = time { publisher.ping }
38
+ expect(duration).to be > SLEEP_FOR
39
+ expect(file_touched?).to eql true
40
+ expect(file_thread_id).to eql Thread.current.object_id.to_s
41
+ end
42
+ end
43
+
44
+ it "takes less than #{SLEEP_FOR} seconds" do
45
+ publisher.add_listener(MyListener.new, async: subject)
46
+ duration = time { publisher.ping }
47
+ expect(duration).to be < SLEEP_FOR
48
+ expect(file_touched?).to eql true
49
+ expect(file_thread_id).to_not eql Thread.current.object_id.to_s
50
+ end
51
+
52
+ def time(&block)
53
+ start = Time.now
54
+ yield
55
+ Time.now - start
56
+ end
57
+
58
+ def file_touched?
59
+ resolution = 0.1
60
+ (SLEEP_FOR / resolution).to_i.times do
61
+ return true if File.exist?(FILE_PATH)
62
+ sleep(resolution)
63
+ end
64
+ return false
65
+ end
66
+
67
+ def file_thread_id
68
+ File.read(FILE_PATH)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,13 @@
1
+ require 'wisper/celluloid'
2
+
3
+ RSpec.describe 'configuration' do
4
+ let(:configuration) { Wisper.configuration }
5
+
6
+ it 'adds celluloid to broadcasters' do
7
+ expect(configuration.broadcasters).to include :celluloid
8
+ end
9
+
10
+ it 'adds celluloid as async broadcaster' do
11
+ expect(configuration.broadcasters[:async]).to be_an_instance_of(Wisper::CelluloidBroadcaster)
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'wisper/celluloid'
5
+
6
+ RSpec.configure do |config|
7
+ config.filter_run :focus
8
+ config.run_all_when_everything_filtered = true
9
+
10
+ if config.files_to_run.one?
11
+ config.default_formatter = 'doc'
12
+ end
13
+
14
+ config.profile_examples = 10
15
+
16
+ config.order = :random
17
+
18
+ Kernel.srand config.seed
19
+
20
+ config.expect_with :rspec do |expectations|
21
+ expectations.syntax = :expect
22
+ end
23
+
24
+ config.mock_with :rspec do |mocks|
25
+ mocks.syntax = :expect
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper/celluloid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisper-celluloid"
8
+ spec.version = Wisper::Celluloid::VERSION
9
+ spec.authors = ["Kris Leech"]
10
+ spec.email = ["kris.leech@gmail.com"]
11
+ spec.summary = "Wisper async publishing using Celluloid"
12
+ spec.description = "Wisper async publishing using Celluloid"
13
+ spec.homepage = "https://github.com/krisleech/wisper-celluloid"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_dependency 'wisper'
26
+ spec.add_dependency 'celluloid'
27
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper-celluloid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kris Leech
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.6'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: wisper
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: celluloid
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :runtime
83
+ description: Wisper async publishing using Celluloid
84
+ email:
85
+ - kris.leech@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/wisper/celluloid.rb
98
+ - lib/wisper/celluloid/version.rb
99
+ - lib/wisper/celluloid_broadcaster.rb
100
+ - spec/celluloid_broadcaster_spec.rb
101
+ - spec/configuration_spec.rb
102
+ - spec/spec_helper.rb
103
+ - wisper-celluloid.gemspec
104
+ homepage: https://github.com/krisleech/wisper-celluloid
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.1.9
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Wisper async publishing using Celluloid
128
+ test_files:
129
+ - spec/celluloid_broadcaster_spec.rb
130
+ - spec/configuration_spec.rb
131
+ - spec/spec_helper.rb