wisper-activejob 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36e471fff54dd21f647ec51638cc1795a56c80bb
4
+ data.tar.gz: fa90ffd3fe28aee6cab99fa6f9606520d3082d14
5
+ SHA512:
6
+ metadata.gz: f753fa7d5f13f9b1530725e3133cfa3f7cccf2d100bf4bfc779ad5aa29cf7214d44112ab34bdfdd553faebbb9cfd24be722f75c54673c41dbf843cd5caecdea6
7
+ data.tar.gz: 215879bb2929802299b23d7dd22adf91fb957c585ff4554ba955b8bc1fcb3fc8b5391785e864acac1aeaa54a324e3af3de02ba0938d551f7a0752b5ab531b75d
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ 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
+ bundler_args: --without=extras
4
+ rvm:
5
+ - jruby-19mode
6
+ - rbx-2
7
+ - 1.9.3
8
+ - 2.2
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'bundler'
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'coveralls', require: false
9
+
10
+ group :extras do
11
+ gem 'pry'
12
+ end
@@ -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,43 @@
1
+ # Wisper::ActiveJob
2
+
3
+ Provides [Wisper](https://github.com/krisleech/wisper) with asynchronous event
4
+ publishing using
5
+ [ActiveJob](https://github.com/rails/rails/tree/master/activejob).
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/wisper-activejob.png)](http://badge.fury.io/rb/wisper-activejob)
8
+ [![Code Climate](https://codeclimate.com/github/krisleech/wisper-activejob.png)](https://codeclimate.com/github/krisleech/wisper-activejob)
9
+ [![Build Status](https://travis-ci.org/krisleech/wisper-activejob.png?branch=master)](https://travis-ci.org/krisleech/wisper-activejob)
10
+ [![Coverage Status](https://coveralls.io/repos/krisleech/wisper-activejob/badge.png?branch=master)](https://coveralls.io/r/krisleech/wisper-activejob?branch=master)
11
+
12
+ ## Installation
13
+
14
+ ```ruby
15
+ gem 'wisper-activejob'
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```ruby
21
+ publisher.subscribe(MyListener, async: true)
22
+ ```
23
+
24
+ The listener must be a class (or module), not an object. This is because ActiveJob
25
+ can not reconstruct the state of an object. Whereas a class has no state.
26
+
27
+ When publshing events the arguments must be simple types as they need to be
28
+ serialized, or the object must include `GlobalID` such as `ActiveRecord` models.
29
+
30
+ * [ActiveJob guide](http://edgeguides.rubyonrails.org/active_job_basics.html)
31
+ * [GlobalID](https://github.com/rails/globalid)
32
+
33
+ ## Compatibility
34
+
35
+ 1.9.3+ including JRuby and Rubinius.
36
+
37
+ See the [build status](https://travis-ci.org/krisleech/wisper-activejob) for details.
38
+
39
+ ## Contributing
40
+
41
+ Please send a [Pull Request](https://github.com/krisleech/wisper-activejob/pulls)
42
+ or an [Issue](https://github.com/krisleech/wisper-activejob/issues) to discuss
43
+ your idea first.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ require 'wisper/active_job/version'
2
+ # require 'active_job'
3
+ require 'rails/all'
4
+ require 'wisper'
5
+ require 'wisper/active_job_broadcaster'
@@ -0,0 +1,5 @@
1
+ module Wisper
2
+ module ActiveJob
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'wisper'
2
+ require 'wisper/active_job/version'
3
+ # require 'active_job'
4
+ require 'rails/all'
5
+
6
+ module Wisper
7
+ class ActiveJobBroadcaster
8
+ def broadcast(subscriber, publisher, event, args)
9
+ Wrapper.perform_later(subscriber.name, event, args)
10
+ end
11
+
12
+ class Wrapper < ::ActiveJob::Base
13
+ queue_as :default
14
+
15
+ def perform(class_name, event, args)
16
+ listener = class_name.constantize
17
+ listener.public_send(event, *args)
18
+ end
19
+ end
20
+
21
+ def self.register
22
+ Wisper.configure do |config|
23
+ config.broadcaster :active_job, ActiveJobBroadcaster.new
24
+ config.broadcaster :async, ActiveJobBroadcaster.new
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ Wisper::ActiveJobBroadcaster.register
@@ -0,0 +1 @@
1
+ require "wisper/active_job"
@@ -0,0 +1,13 @@
1
+ require 'wisper/active_job'
2
+
3
+ RSpec.describe 'configuration' do
4
+ let(:configuration) { Wisper.configuration }
5
+
6
+ it 'configures active_job as a broadcaster' do
7
+ expect(configuration.broadcasters).to include :active_job
8
+ end
9
+
10
+ it 'configures sidekiq as default async broadcaster' do
11
+ expect(configuration.broadcasters[:async]).to be_an_instance_of(Wisper::ActiveJobBroadcaster)
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ require 'wisper/active_job'
2
+
3
+ RSpec.describe 'integration tests:' do
4
+ let(:publisher) do
5
+ Class.new do
6
+ include Wisper::Publisher
7
+
8
+ def run
9
+ broadcast(:it_happened, 'hello, world')
10
+ end
11
+ end.new
12
+ end
13
+
14
+ let(:subscriber) do
15
+ Class.new do
16
+ def self.it_happened
17
+ # noop
18
+ end
19
+ end
20
+ end
21
+
22
+ let(:adapter) { ActiveJob::Base.queue_adapter }
23
+
24
+ before do
25
+ ActiveJob::Base.queue_adapter = :test
26
+ ActiveJob::Base.queue_adapter.enqueued_jobs.clear
27
+ end
28
+
29
+ it 'puts job on ActiveJob queue' do
30
+ publisher.subscribe(subscriber, async: Wisper::ActiveJobBroadcaster.new)
31
+
32
+ publisher.run
33
+
34
+ expect(adapter.enqueued_jobs.size).to eq 1
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ require 'coveralls'
2
+ require 'simplecov'
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+
6
+ SimpleCov.start
7
+
8
+ RSpec.configure do |config|
9
+ config.expect_with :rspec do |expectations|
10
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
11
+ end
12
+
13
+ config.mock_with :rspec do |mocks|
14
+ mocks.verify_partial_doubles = true
15
+ end
16
+
17
+ config.filter_run :focus
18
+ config.run_all_when_everything_filtered = true
19
+
20
+ config.disable_monkey_patching!
21
+
22
+ config.warnings = true
23
+
24
+ if config.files_to_run.one?
25
+ config.default_formatter = 'doc'
26
+ end
27
+
28
+ config.profile_examples = 10
29
+
30
+ config.order = :random
31
+
32
+ Kernel.srand config.seed
33
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper/active_job/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisper-activejob"
8
+ spec.version = Wisper::ActiveJob::VERSION
9
+ spec.authors = ["Kris Leech"]
10
+ spec.email = ["kris.leech@gmail.com"]
11
+ spec.summary = "Provides Wisper with asynchronous event publishing using ActiveJob"
12
+ spec.description = "Provides Wisper with asynchronous event publishing using ActiveJob"
13
+ spec.homepage = "https://github.com/krisleech/wisper-activejob"
14
+
15
+ spec.required_ruby_version = '>= 1.9.3'
16
+
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'wisper'
24
+ # spec.add_dependency 'activejob'
25
+ spec.add_dependency 'rails', '4.2.0.beta2'
26
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper-activejob
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-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wisper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.2.0.beta2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 4.2.0.beta2
41
+ description: Provides Wisper with asynchronous event publishing using ActiveJob
42
+ email:
43
+ - kris.leech@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/wisper/active_job.rb
56
+ - lib/wisper/active_job/version.rb
57
+ - lib/wisper/active_job_broadcaster.rb
58
+ - lib/wisper/activejob.rb
59
+ - spec/configuration_spec.rb
60
+ - spec/integration_spec.rb
61
+ - spec/spec_helper.rb
62
+ - wisper-activejob.gemspec
63
+ homepage: https://github.com/krisleech/wisper-activejob
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.3
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Provides Wisper with asynchronous event publishing using ActiveJob
87
+ test_files:
88
+ - spec/configuration_spec.rb
89
+ - spec/integration_spec.rb
90
+ - spec/spec_helper.rb