resugan 0.1.7 → 0.1.8

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: 125a46c660b15e707e2e9c7ff8566b1f396748ae
4
- data.tar.gz: 9902cfe5e810f491fed9580e48b539bf99c5048e
3
+ metadata.gz: 7b0da82adc30cfab65fae130355e751f37aaa0ec
4
+ data.tar.gz: ba8ca7543faf7d229e11a986f0376ce65b4a880b
5
5
  SHA512:
6
- metadata.gz: 058d79aec3ee6752265d00687f6bd4644ddb3f2c27f6016b764cbad4e8a84a1fbe7a5e4ef10c113c10c68d028118f2eb3eec395049a8731c7ceba5ebfccc6478
7
- data.tar.gz: 2e9fd51c681d1bc04323037c6a41ea1fb8e76d0dac678adba2b0dbc4c89a01fbf18ccb5d9e28aeddf20b1492942964b3d0c804bf72765dd02e26166141d357f8
6
+ metadata.gz: 6f15686a8c362eb7206e3160517026ceb5d7a29ef1155ae8c863319524ee2e1713b22d7d9621d5b885b6046ff9ce2f18e5682ccc72de3214d62c5f3be92777b6
7
+ data.tar.gz: b6a4838b230915d920ff92c9814f7e8ec8cd4b35ffe6f275d38a2ac0b211c4cafef897124868141de5c9fb198f4b0f3e920772b1c4870a5154b358db5e822253
data/README.md CHANGED
@@ -59,6 +59,37 @@ hello! someone said hay!
59
59
  Note that your listener will be executed once even if an event has been fired
60
60
  multiple times. However params will contain the payload of both events. This allows you to batch together requests and efficiently dispatch them as a group.
61
61
 
62
+ # Object helpers
63
+
64
+ Helpers are available to make listening firing events a little bit cleaner:
65
+
66
+ ```ruby
67
+ class TestObject
68
+ include Resugan::ObjectHelpers
69
+ end
70
+ ```
71
+
72
+ This basically allows for the attach_hook to be available
73
+
74
+ ```ruby
75
+ class TestObject
76
+ include Resugan::ObjectHelpers
77
+
78
+ def method2
79
+ _fire :event1
80
+ end
81
+
82
+ def method3
83
+ _fire :event2, param1: "hello"
84
+ end
85
+
86
+ attach_hook :method2
87
+ attach_hook :method3, namespace: "namespace1"
88
+ end
89
+ ```
90
+
91
+ What this does is it essentially wraps the specified methods inside a resugan block.
92
+
62
93
  Please see spec/resugan_spec.rb for more examples and details.
63
94
 
64
95
  ## namespaces
@@ -115,6 +146,41 @@ Or assign it to a specific namespace:
115
146
  Resugan::Kernel.register_dispatcher(MyCustomerDispatcher, 'CustomGroup')
116
147
  ```
117
148
 
149
+ ## Debugging
150
+
151
+ Sometimes you need to track where events are fired. You can do so by enabling line tracing:
152
+
153
+ ```ruby
154
+ Resugan::Kernel.enable_line_trace true
155
+ ```
156
+
157
+ Line source should now be passed as params everytime you fire an event. You can also
158
+ view it by dumping a resugan context.
159
+
160
+ ```ruby
161
+ puts resugan {
162
+ _fire :event1
163
+ }.dump
164
+ ```
165
+
166
+ ```ruby
167
+ {:event1=>[{:params=>{:_source=>"/Users/jedld/workspace/resugan/spec/resugan_spec.rb:144:in `block (5 levels) in <top (required)>'"}}]}
168
+ ```
169
+
170
+
171
+
172
+ ## Related Projects
173
+
174
+ Below are projects that extend resugan.
175
+
176
+ Resugan Worker
177
+ --------------
178
+
179
+ A project that wraps resugan listeners to be consumed using an external worker.
180
+ Can also be used as a sample on how to extend resugan.
181
+
182
+ https://github.com/jedld/resugan-worker
183
+
118
184
  ## Development
119
185
 
120
186
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,6 +5,10 @@ module Resugan
5
5
  @events = {}
6
6
  end
7
7
 
8
+ def namespace
9
+ @namespace
10
+ end
11
+
8
12
  def register(event, params = {})
9
13
  event = event.to_sym
10
14
  payload = { params: params }
@@ -19,5 +23,9 @@ module Resugan
19
23
  dispatcher = Resugan::Kernel.dispatcher_for(@namespace)
20
24
  dispatcher.dispatch(@namespace, @events)
21
25
  end
26
+
27
+ def dump
28
+ @events
29
+ end
22
30
  end
23
31
  end
@@ -1,5 +1,14 @@
1
1
  module Resugan
2
2
  class Kernel
3
+ # flag to log the line source where a fire was executed
4
+ def self.enable_line_trace(enable)
5
+ @enable = enable
6
+ end
7
+
8
+ def self.line_trace_enabled?
9
+ @enable || false
10
+ end
11
+
3
12
  def self.set_default_dispatcher(dispatcher)
4
13
  @default_dispatcher ||= dispatcher.new
5
14
  end
@@ -7,9 +7,13 @@ class Object
7
7
 
8
8
  context = current_thread.pop_resugan_context
9
9
  context.invoke
10
+
11
+ context
10
12
  end
11
13
 
12
14
  def _fire(event, params = {})
15
+ params[:_source] = caller[0] if Resugan::Kernel.line_trace_enabled?
16
+
13
17
  current_thread = Thread.current
14
18
  if current_thread.resugan_context
15
19
  current_thread.resugan_context.register(event, params)
@@ -1,3 +1,3 @@
1
1
  module Resugan
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resugan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Emmanuel Dayo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-28 00:00:00.000000000 Z
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.4.5.1
116
+ rubygems_version: 2.5.1
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: simple, powerful and unobstrusive event framework for ruby