motion_flux 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/lib/motion_flux/action.rb +9 -1
- data/lib/motion_flux/dispatcher.rb +31 -33
- data/lib/motion_flux/store.rb +15 -0
- data/lib/motion_flux/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d507b7c085d4fd6879c0fa57a2441a139decac6e
|
4
|
+
data.tar.gz: ac6b3a180bee707c5df7070cb8ce859015859d5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e354608a93ba7d91043d29cffff4fd07f2c847a8e4ff3e0c9cfd34d3c5da63db77cabc54ab04351dd34071e596656ed646f6d25c7352798cc34fd613f40aa15
|
7
|
+
data.tar.gz: d5bfa3d67fb067a2313608d5eeb1affb6becf1e4b192d770fa4b9a3d156405996e749893461ec4f8068ee364423a203ebf74f766ee05f11d037da9a39c1d9db9
|
data/.travis.yml
CHANGED
data/lib/motion_flux/action.rb
CHANGED
@@ -12,7 +12,15 @@ module MotionFlux
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def dispatch
|
15
|
-
|
15
|
+
Dispatcher.dispatch self
|
16
16
|
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def dispatch message, *args
|
20
|
+
new(message, *args).dispatch
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
extend ClassMethods
|
17
25
|
end
|
18
26
|
end
|
@@ -1,46 +1,44 @@
|
|
1
1
|
module MotionFlux
|
2
|
-
|
3
|
-
|
4
|
-
def subscribers
|
5
|
-
@subscribers ||= Hash.new { |hash, key| hash[key] = [] }
|
6
|
-
end
|
2
|
+
module Dispatcher
|
3
|
+
module_function
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
5
|
+
def subscribers
|
6
|
+
@subscribers ||= Hash.new { |hash, key| hash[key] = [] }
|
7
|
+
end
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def register store, action
|
10
|
+
puts "#{store} is registered on #{action}"
|
11
|
+
subscribers[action] << store
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
def clear
|
15
|
+
subscribers.clear
|
16
|
+
end
|
17
|
+
|
18
|
+
def dispatch action
|
19
|
+
exclusive_run action do
|
20
|
+
subscribers[action.class].each do |store|
|
21
|
+
if store.respond_to? action.message
|
22
|
+
store.send action.message, action
|
23
|
+
else
|
24
|
+
puts "#{store}##{action.message} is not defined."
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
30
|
+
def exclusive_run action, &proc
|
31
|
+
if @current_action
|
32
|
+
puts 'cascading action dispatch is not allowed.'
|
33
|
+
puts "#{@current_action} is on process."
|
34
|
+
else
|
35
|
+
@current_action = action
|
36
|
+
begin
|
37
|
+
proc.call
|
38
|
+
ensure
|
39
|
+
@current_action = nil
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
extend ClassMethods
|
45
43
|
end
|
46
44
|
end
|
data/lib/motion_flux/store.rb
CHANGED
@@ -9,6 +9,21 @@ module MotionFlux
|
|
9
9
|
MotionFlux::Dispatcher.register instance, action
|
10
10
|
end
|
11
11
|
|
12
|
+
def store_attribute *attrs
|
13
|
+
attrs.each do |attr|
|
14
|
+
attributes << attr
|
15
|
+
|
16
|
+
attr_reader attr
|
17
|
+
define_singleton_method attr do
|
18
|
+
instance.send attr
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def attributes
|
24
|
+
@attributes ||= []
|
25
|
+
end
|
26
|
+
|
12
27
|
def instance
|
13
28
|
@instance ||= new
|
14
29
|
end
|
data/lib/motion_flux/version.rb
CHANGED