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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d9511e7f5144c24d67746439ca81e028226abe1
4
- data.tar.gz: ab309158b5fc77c74910cff5c73a938c23734767
3
+ metadata.gz: d507b7c085d4fd6879c0fa57a2441a139decac6e
4
+ data.tar.gz: ac6b3a180bee707c5df7070cb8ce859015859d5f
5
5
  SHA512:
6
- metadata.gz: 57192a8a003fb9aa3614a23a8c9d8231faa4710bb008d0a4d7661753d0867345b632548c38bc079998a0205fc31c743cc69b6a81d40475d990e289f2a9c0b3be
7
- data.tar.gz: c2c39d3abc3a7ae976839773e6f8c7629ea3857d852e969631af7295e2f15ec59d9881d2a5e7355708f3080387800e286d8d95e24021e6bb2464ef3a2365a09b
6
+ metadata.gz: 9e354608a93ba7d91043d29cffff4fd07f2c847a8e4ff3e0c9cfd34d3c5da63db77cabc54ab04351dd34071e596656ed646f6d25c7352798cc34fd613f40aa15
7
+ data.tar.gz: d5bfa3d67fb067a2313608d5eeb1affb6becf1e4b192d770fa4b9a3d156405996e749893461ec4f8068ee364423a203ebf74f766ee05f11d037da9a39c1d9db9
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.4
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -12,7 +12,15 @@ module MotionFlux
12
12
  end
13
13
 
14
14
  def dispatch
15
- MotionFlux::Dispatcher.dispatch self
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
- class Dispatcher
3
- module ClassMethods
4
- def subscribers
5
- @subscribers ||= Hash.new { |hash, key| hash[key] = [] }
6
- end
2
+ module Dispatcher
3
+ module_function
7
4
 
8
- def register store, action
9
- puts "#{store} is registered on #{action}"
10
- subscribers[action] << store
11
- end
5
+ def subscribers
6
+ @subscribers ||= Hash.new { |hash, key| hash[key] = [] }
7
+ end
12
8
 
13
- def clear
14
- subscribers.clear
15
- end
9
+ def register store, action
10
+ puts "#{store} is registered on #{action}"
11
+ subscribers[action] << store
12
+ end
16
13
 
17
- def dispatch action
18
- exclusive_run action do
19
- subscribers[action.class].each do |store|
20
- if store.respond_to? action.message
21
- store.send action.message, action
22
- else
23
- puts "#{store}##{action.message} is not defined."
24
- end
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
- def exclusive_run action, &proc
30
- if @current_action
31
- puts 'cascading action dispatch is not allowed.'
32
- puts "#{@current_action} is on process."
33
- else
34
- @current_action = action
35
- begin
36
- proc.call
37
- ensure
38
- @current_action = nil
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module MotionFlux
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion_flux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kayhide