metacosm 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/metacosm/model.rb +27 -6
- data/lib/metacosm/simulation.rb +4 -6
- data/lib/metacosm/version.rb +1 -1
- data/spec/metacosm_spec.rb +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 793f2bede876f5dd2cb43e61fb87b70d212ee085
|
|
4
|
+
data.tar.gz: 943eb4743ba08ea7945cfec6cd397a25d6d19c6f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11caa1078cbdd52df31ceee28df67f304de7fe66793151d84897331d314b623a9cb1b48741e1efee96dce6c1d04513313ee91198330de9c8d2cc38feeb19a8e6
|
|
7
|
+
data.tar.gz: 594e824dae825b635865ca78375cd105e7f7b6b962e180949cb379daab17dbf6b8889a6a0016ff28466d1d979becb1e0acf41a91495e541ec03ea5f38139c50d
|
data/lib/metacosm/model.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
module Metacosm
|
|
2
2
|
class Model
|
|
3
3
|
include PassiveRecord
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
before_create :register_observer
|
|
5
|
+
after_create :emit_creation_event
|
|
6
|
+
after_update :emit_updation_event
|
|
7
|
+
after_destroy :emit_destruction_event
|
|
6
8
|
|
|
7
9
|
private
|
|
8
10
|
def register_observer
|
|
@@ -17,6 +19,10 @@ module Metacosm
|
|
|
17
19
|
emit(updation_event) if updated_event_class
|
|
18
20
|
end
|
|
19
21
|
|
|
22
|
+
def emit_destruction_event
|
|
23
|
+
emit(destruction_event) if destroyed_event_class
|
|
24
|
+
end
|
|
25
|
+
|
|
20
26
|
def attributes_with_external_id
|
|
21
27
|
attrs = to_h
|
|
22
28
|
if attrs.key?(:id)
|
|
@@ -51,14 +57,29 @@ module Metacosm
|
|
|
51
57
|
assemble_event updated_event_class
|
|
52
58
|
end
|
|
53
59
|
|
|
60
|
+
def destruction_event
|
|
61
|
+
assemble_event destroyed_event_class
|
|
62
|
+
end
|
|
63
|
+
|
|
54
64
|
def created_event_class
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
@created_event_class ||= (
|
|
66
|
+
created_event_name = self.class.name + "CreatedEvent"
|
|
67
|
+
Object.const_get(created_event_name) rescue nil
|
|
68
|
+
)
|
|
57
69
|
end
|
|
58
70
|
|
|
59
71
|
def updated_event_class
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
@updated_event_class ||= (
|
|
73
|
+
updated_event_name = self.class.name + "UpdatedEvent";
|
|
74
|
+
Object.const_get(updated_event_name) rescue nil
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def destroyed_event_class
|
|
79
|
+
@destroyed_event_class ||= (
|
|
80
|
+
destroyed_event_name = self.class.name + "DestroyedEvent";
|
|
81
|
+
Object.const_get(destroyed_event_name) rescue nil
|
|
82
|
+
)
|
|
62
83
|
end
|
|
63
84
|
|
|
64
85
|
def blacklisted_attribute_names
|
data/lib/metacosm/simulation.rb
CHANGED
|
@@ -6,7 +6,6 @@ module Metacosm
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def fire(command)
|
|
9
|
-
# p [ :firing, command: command ]
|
|
10
9
|
command_queue.push(command)
|
|
11
10
|
end
|
|
12
11
|
|
|
@@ -32,14 +31,13 @@ module Metacosm
|
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
def mutex
|
|
35
|
-
@mutex = Mutex.new
|
|
34
|
+
@mutex = Mutex.new
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
def apply(command)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
#end
|
|
38
|
+
mutex.synchronize do
|
|
39
|
+
handler_for(command).handle(command.attrs)
|
|
40
|
+
end
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
def receive(event, record: true)
|
data/lib/metacosm/version.rb
CHANGED
data/spec/metacosm_spec.rb
CHANGED
|
@@ -34,6 +34,7 @@ describe "a simple simulation (fizzbuzz)" do
|
|
|
34
34
|
|
|
35
35
|
sleep 0.1
|
|
36
36
|
expect(counter_view.value).to eq(1) # => 1
|
|
37
|
+
sim.halt!
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
context "one command once" do
|
|
@@ -66,9 +67,10 @@ describe "a simple simulation (fizzbuzz)" do
|
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
context "one command ten times" do
|
|
69
|
-
|
|
70
|
+
it 'is expected to play fizz buzz' do
|
|
71
|
+
simulation.conduct!
|
|
70
72
|
expect {
|
|
71
|
-
10.times { simulation.
|
|
73
|
+
10.times { simulation.fire(increment_counter); sleep 0.1 }
|
|
72
74
|
}.to output(%w[ 1 2 fizz 4 buzz fizz 7 8 fizz buzz ].join("\n") + "\n").to_stdout
|
|
73
75
|
end
|
|
74
76
|
end
|
|
@@ -83,7 +85,7 @@ describe "a simple simulation (fizzbuzz)" do
|
|
|
83
85
|
|
|
84
86
|
describe "the last event" do
|
|
85
87
|
subject { last_event }
|
|
86
|
-
|
|
88
|
+
it { is_expected.to be_a CounterIncrementedEvent }
|
|
87
89
|
end
|
|
88
90
|
|
|
89
91
|
describe "querying for the counter value" do
|
|
@@ -115,10 +117,10 @@ describe "a simple simulation (fizzbuzz)" do
|
|
|
115
117
|
threads.map(&:join)
|
|
116
118
|
end
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
xdescribe "the last event" do
|
|
119
121
|
subject { last_event }
|
|
120
122
|
|
|
121
|
-
|
|
123
|
+
it { is_expected.to be_a BuzzEvent }
|
|
122
124
|
end
|
|
123
125
|
|
|
124
126
|
describe "querying for the counter value" do
|
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.
|
|
4
|
+
version: 0.2.2
|
|
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-02-
|
|
11
|
+
date: 2016-02-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: passive_record
|