metacosm 0.2.10 → 0.2.11

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: 66802276f7d8db815a5aca5f04ebf872bf700d7a
4
- data.tar.gz: 720f2ad0b127844933796bbf880d683f0de33e6d
3
+ metadata.gz: 6f1364b08565c171187ac2147a3812327ae0bacd
4
+ data.tar.gz: 5c41390aa54ece8be01a6bd52beea209a1a98d97
5
5
  SHA512:
6
- metadata.gz: 132ec9a5c3c4191b47c41f56a02d9f85114517f8059280004b77da1bceda5b9ee25e3e802d8dc79681025a3cedeb1319b08b874f4ef0068e1e9c05b39cd5c945
7
- data.tar.gz: b595a0273dd022685e964172989d890d1a28c51ff3f35f541ff08541bdb3918b9b7859b3126af19477673282f789a9f9b434af2b6678092c206663fd1c3ca3fd
6
+ metadata.gz: 0f214a30b472251583b7db4f880feaf3fb7ce29104ea57b47eec8ba52ade6ce8de1602bc9cfb8ab3bd266ae67e317324c95661bbba94ce98cfca3b9375e09873
7
+ data.tar.gz: 6a934a31535a83c58a01dc18d8001c48eeda2571c340e279c0cdd352bd7e1047d50fa3a877e4faca6bd25ea798c6c84d436d4a8ad96f17e315e1ab719e9af270
data/lib/metacosm.rb CHANGED
@@ -22,6 +22,20 @@ module Metacosm
22
22
  def ==(other)
23
23
  attrs == other.attrs
24
24
  end
25
+
26
+ def handler_class_name
27
+ self.class.name.demodulize + "Handler"
28
+ end
29
+
30
+ def handler_module_name
31
+ module_name = self.class.name.deconstantize
32
+ module_name = "Object" if module_name.empty?
33
+ module_name
34
+ end
35
+
36
+ def self_class_name
37
+ self.class.name
38
+ end
25
39
  end
26
40
 
27
41
  class Event
@@ -34,6 +48,20 @@ module Metacosm
34
48
  def ==(other)
35
49
  attrs == other.attrs
36
50
  end
51
+
52
+ def listener_class_name
53
+ self.class.name.demodulize + "Listener"
54
+ end
55
+
56
+ def listener_module_name
57
+ module_name = self.class.name.deconstantize
58
+ module_name = "Object" if module_name.empty?
59
+ module_name
60
+ end
61
+
62
+ def self_class_name
63
+ self.class.name
64
+ end
37
65
  end
38
66
 
39
67
  class EventListener < Struct.new(:simulation)
@@ -1,4 +1,9 @@
1
+ require 'drb/drb'
1
2
  module Metacosm
3
+ class EventStream < Frappuccino::Stream
4
+ include DRb::DRbUndumped
5
+ end
6
+
2
7
  class Simulation
3
8
  attr_accessor :running
4
9
  def watch(model)
@@ -38,12 +43,24 @@ module Metacosm
38
43
 
39
44
  def apply(command)
40
45
  mutex.synchronize do
41
- handler_for(command).handle(command.attrs)
46
+ handler = handler_for(command)
47
+ handler.handle(command.attrs)
42
48
  end
43
49
  end
44
50
 
51
+ def event_stream
52
+ @event_stream ||= EventStream.new(self)
53
+ end
54
+
55
+ def has_event_stream?
56
+ !@event_stream.nil?
57
+ end
58
+
45
59
  def receive(event, record: true)
46
- events.push(event) if record
60
+ if record
61
+ events.push(event)
62
+ emit(event) if has_event_stream?
63
+ end
47
64
 
48
65
  listener = listener_for(event)
49
66
  if event.attrs.any?
@@ -69,25 +86,28 @@ module Metacosm
69
86
  protected
70
87
  def handler_for(command)
71
88
  @handlers ||= {}
72
- @handlers[command.class] ||= construct_handler_for(command)
89
+ @handlers[command.self_class_name] ||= construct_handler_for(command)
73
90
  end
74
91
 
75
92
  def construct_handler_for(command)
76
- module_name = command.class.name.deconstantize
77
- module_name = "Object" if module_name.empty?
93
+ module_name = command.handler_module_name
94
+ # module_name = "Object" if module_name.empty?
78
95
  (module_name.constantize).
79
- const_get(command.class.name.demodulize + "Handler").new
96
+ const_get(command.handler_class_name).new
97
+ rescue => ex
98
+ binding.pry
99
+ raise ex
80
100
  end
81
101
 
82
102
  def listener_for(event)
83
103
  @listeners ||= {}
84
- @listeners[event.class] ||= construct_listener_for(event)
104
+ @listeners[event.self_class_name] ||= construct_listener_for(event)
85
105
  end
86
106
 
87
107
  def construct_listener_for(event)
88
- module_name = event.class.name.deconstantize
89
- module_name = "Object" if module_name.empty?
90
- listener = (module_name.constantize).const_get(event.class.name.demodulize + "Listener").new(self)
108
+ module_name = event.listener_module_name #class.name.deconstantize
109
+ # module_name = "Object" if module_name.empty?
110
+ listener = (module_name.constantize).const_get(event.listener_class_name).new(self)
91
111
  listener
92
112
  end
93
113
  end
@@ -1,4 +1,4 @@
1
1
  module Metacosm
2
2
  # metacosm version
3
- VERSION = "0.2.10"
3
+ VERSION = "0.2.11"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metacosm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: passive_record