loomio_event 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: 1dfd6a750f60c8f562c3a1954b4cfcdfa116e35b
4
+ data.tar.gz: dadd71205c139be3f5bd0ea451e5b6f854da5792
5
+ SHA512:
6
+ metadata.gz: f2687523217d034db3fadee88eaf95709cd188bdd97799705b378543cdd27532ae86bc09154d13fca40083c9713cc42a47d70300465ec0bf67be6541392fe8d8
7
+ data.tar.gz: 45503275de75089353f7f997ed607d8326dd9ee22f52a8833b6b73194a31d16af08b294ed7c70d0d0b6452af268251fb83ec7674cfd8b60685bdd94ccb9baee7
@@ -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
@@ -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
@@ -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.
@@ -0,0 +1,49 @@
1
+ # Loomio::Event
2
+
3
+ Loomio::Event 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 'loomio_event'
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::Event.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::Event.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).
@@ -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 Event
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'
2
+
3
+ module Loomio
4
+ class Event
5
+ VERSION = "0.0.1"
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/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "loomio_event"
8
+ spec.version = Loomio::Event::VERSION
9
+ spec.authors = ["James Kiesel (gdpelican)"]
10
+ spec.email = ["james@loomio.org"]
11
+
12
+ spec.summary = "LoomioEvent 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
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
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.rb
83
+ - lib/loomio/event/version.rb
84
+ - loomio_event.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: LoomioEvent allows for simple pub/sub style event architecture in your rails
109
+ app
110
+ test_files: []