koine-event_manager 1.0.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b203d892bc234ce8366802859308e8c9656da9e
4
- data.tar.gz: fd4a6216c688e50ac46ec059cd7cf0c8e1bb9a77
3
+ metadata.gz: 775de95f0d2768e1147c12eea5a66dd28fd23fee
4
+ data.tar.gz: 6bb2f1ef07c98614d119a615769f67e318f32e77
5
5
  SHA512:
6
- metadata.gz: fbdc01af9f5a357354aadae2fc8350fc5023dd8add92148ac3ffba7dd229519e7ddc8b81656cd347fa919c02e2e4f9f3b06bacdcd355ba327cbc4d8fa40c9ae2
7
- data.tar.gz: e175d834d2aa00b61b561996d231d340f3345224ca4f7e09c4f67a8854c2d5b003dc2f57c9eef34da0d86b1cd286b64b1a4f93039a998c62d8809ccaf8edb0db
6
+ metadata.gz: 0c6b9922bd907cd760a065bb74a564142b6817881a213e52b0674535beb223b954eda7e418e389c101b71a29ffbde0ab7d3b98329318453a59d2e57e9d5896dc
7
+ data.tar.gz: 7c653751ff81a31f53ec7267aa952225b61de01f50b9e1181a3b506cdd18e22270c3131e043ae25383e7c3a3a95b32bfacee96c317b1c077930711bd793b7ccd
data/README.md CHANGED
@@ -83,6 +83,38 @@ And trigger the event on the event manager
83
83
  event_manager.trigger(UserSignedIn.new(some_user))
84
84
  ```
85
85
 
86
+ ## Adding event manager awareness to your classes
87
+
88
+ **CAUTION**: This make use of the singleton instance of event manager.
89
+ Singletons are usually a bad idea, so prefer dependency injection over
90
+ singleton instances.
91
+
92
+ ```ruby
93
+ require "koine/event_manager/event_manager_aware"
94
+
95
+ class MyModel
96
+ include Koine::EventManager::EventManagerAware
97
+
98
+ def some_method
99
+ event_manager.trigger(SomeEvent.new(foo: :bar))
100
+ end
101
+ end
102
+ ```
103
+
104
+ The above is the same as:
105
+
106
+ ```ruby
107
+ class MyModel
108
+ def some_method
109
+ event_manager.trigger(SomeEvent.new(foo: :bar))
110
+ end
111
+
112
+ def event_manager
113
+ Koine::EventManager::EventManager.instance
114
+ end
115
+ end
116
+ ```
117
+
86
118
  ## Development
87
119
 
88
120
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -28,6 +28,10 @@ module Koine
28
28
  def listeners
29
29
  @listners ||= []
30
30
  end
31
+
32
+ def self.instance
33
+ @@instance ||= new
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -0,0 +1,13 @@
1
+ module Koine
2
+ module EventManager
3
+ module EventManagerAware
4
+ def self.included(klass)
5
+ klass.instance_eval do
6
+ define_method "event_manager" do
7
+ Koine::EventManager::EventManager.instance
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Koine
2
2
  module EventManager
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koine-event_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Jacobus
@@ -115,6 +115,7 @@ files:
115
115
  - lib/koine/event_manager.rb
116
116
  - lib/koine/event_manager/event_listener.rb
117
117
  - lib/koine/event_manager/event_manager.rb
118
+ - lib/koine/event_manager/event_manager_aware.rb
118
119
  - lib/koine/event_manager/version.rb
119
120
  homepage: https://github.com/mjacobus/koine-event-manager
120
121
  licenses: