loomio_event_bus 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e7ca2a4d74f1962b46069dde5d63cd8a95f9db4
4
+ data.tar.gz: 573697b04ea3f6e3400307ca055b6154ef470d8f
5
+ SHA512:
6
+ metadata.gz: 5582d6866b205ed9fe37abaae8a6936954c7fd3a0ff875871293eae8516415c34919ee266580c3e821cd876bf4007974b20bdfe7dbc937fbb1ae15d07f5081c4
7
+ data.tar.gz: 4b8a1ee9a72bf8cde76876910e870266d9558909e32b1874529f564d3752c0eab89a4d25f79c7ba9c1584806061c3394db9243b79104056f7ea400c2fa66a5a4
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .git
11
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :development, :test do
5
+ gem 'byebug', require: nil
6
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 James Kiesel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Loomio::Event
2
+
3
+ EventBus is a simple way to perform pub-sub style events from within your rails app.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'event_bus'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install event_bus
20
+
21
+ ## Usage
22
+
23
+ Loomio Event caters to a Publish / Subscribe style for rails events. To listen to an event, create an initializer with the following:
24
+
25
+ ```ruby
26
+ Loomio::EventBus.configure do |config|
27
+ config.listen('my_event_name') { |param| puts param }
28
+ end
29
+ ```
30
+
31
+ NB: `listen` can take multiple event names for the same block, which can take an arbitrary number of params:
32
+
33
+ ```ruby
34
+ config.listen('my_event_name', 'my_other_event_name') { |param1, param2| puts "#{param1}, #{param2}" }
35
+ ```
36
+
37
+ Then, to trigger the event in your application, call `broadcast`, and pass it your parameters, like so:
38
+
39
+ ```ruby
40
+ Loomio::EventBus.broadcast('my_event_name', 'Hello, world!')
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/loomio/loomio_event. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new :test do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'spec'
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ t.verbose = true
11
+ t.warning = false
12
+ end
@@ -0,0 +1,31 @@
1
+ module Loomio
2
+ class EventBus
3
+
4
+ def self.configure
5
+ yield self
6
+ end
7
+
8
+ def self.broadcast(event, *params)
9
+ listeners[event].each { |listener| listener.call(*params) }
10
+ end
11
+
12
+ def self.listen(*events, &block)
13
+ events.each { |event| listeners[event].add(block) }
14
+ end
15
+
16
+ def self.deafen(*events, &block)
17
+ events.each { |event| listeners[event].delete(block) }
18
+ end
19
+
20
+ def self.clear
21
+ @@listeners = nil
22
+ end
23
+
24
+ def self.listeners
25
+ @@listeners ||= Hash.new { |hash, key| hash[key] = Set.new }
26
+ end
27
+ private_class_method :listeners
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'loomio/event_bus'
2
+
3
+ module Loomio
4
+ class EventBus
5
+ VERSION = "0.0.3"
6
+ end
7
+ 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 'loomio/event_bus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "loomio_event_bus"
8
+ spec.version = Loomio::EventBus::VERSION
9
+ spec.authors = ["James Kiesel (gdpelican)"]
10
+ spec.email = ["james@loomio.org"]
11
+
12
+ spec.summary = "Loomio::EventBus allows for simple pub/sub style event architecture in your rails app"
13
+ spec.homepage = "http://www.github.com/loomio/event_bus"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rails", "~> 4.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loomio_event_bus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - James Kiesel (gdpelican)
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - james@loomio.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/loomio/event_bus.rb
83
+ - lib/loomio/event_bus/version.rb
84
+ - loomio_event_bus.gemspec
85
+ homepage: http://www.github.com/loomio/event_bus
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.5.1
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Loomio::EventBus allows for simple pub/sub style event architecture in your
109
+ rails app
110
+ test_files: []