metacosm 0.2.1 → 0.2.2

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: 1b138d82f2651b9e0ea3f7d6fa5a9987adfe67a8
4
- data.tar.gz: e138e5284daa077a5562ce9646be44b981190b02
3
+ metadata.gz: 793f2bede876f5dd2cb43e61fb87b70d212ee085
4
+ data.tar.gz: 943eb4743ba08ea7945cfec6cd397a25d6d19c6f
5
5
  SHA512:
6
- metadata.gz: f78915da7851bedb4451e21b0c6b654ae707a6acd9203fdb002f482113ecd4de356443ca4886f40758a920b5dbfff413ec27b744738c8f33fe210b6b9b9d487f
7
- data.tar.gz: d65490b545a8bf85beed30c1cf2b4dc5d187902d016b47b7a8b588973ca2ba7e0618180708a4e1a467ebe72ecc5cb0a23c9541fc6c764b6e6ca58d7af152a45e
6
+ metadata.gz: 11caa1078cbdd52df31ceee28df67f304de7fe66793151d84897331d314b623a9cb1b48741e1efee96dce6c1d04513313ee91198330de9c8d2cc38feeb19a8e6
7
+ data.tar.gz: 594e824dae825b635865ca78375cd105e7f7b6b962e180949cb379daab17dbf6b8889a6a0016ff28466d1d979becb1e0acf41a91495e541ec03ea5f38139c50d
@@ -1,8 +1,10 @@
1
1
  module Metacosm
2
2
  class Model
3
3
  include PassiveRecord
4
- after_create :register_observer, :emit_creation_event
5
- after_update :emit_updation_event
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
- created_event_name = self.class.name + "CreatedEvent"
56
- Object.const_get(created_event_name) rescue nil
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
- updated_event_name = self.class.name + "UpdatedEvent"
61
- Object.const_get(updated_event_name) rescue nil
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
@@ -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
- #mutex.synchronize do
40
- # p [ :applying, command: command ]
41
- handler_for(command).handle(command.attrs)
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)
@@ -1,4 +1,4 @@
1
1
  module Metacosm
2
2
  # metacosm version
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
@@ -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
- xit 'is expected to play fizz buzz' do
70
+ it 'is expected to play fizz buzz' do
71
+ simulation.conduct!
70
72
  expect {
71
- 10.times { simulation.apply(increment_counter) }
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
- xit { is_expected.to be_a BuzzEvent }
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
- describe "the last event" do
120
+ xdescribe "the last event" do
119
121
  subject { last_event }
120
122
 
121
- xit { is_expected.to be_a BuzzEvent }
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.1
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-28 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: passive_record