sandthorn 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: 5ea77d4f178bf3c2124f48fbe2e5b12a406cf787
4
- data.tar.gz: e671b7b29d552b10251c335e73d4bfa5280b9614
3
+ metadata.gz: 570d52af1a092035a72a6db14afb0c43ec61ae48
4
+ data.tar.gz: 39f92e0f586d6af40ec7d1b0c9eacdf7c08827ae
5
5
  SHA512:
6
- metadata.gz: 417397fc0a413067e0e1756a325444867aaa9c8e5fd5d7bbb8b8553628f3144987464093e423d07de5bf6c44eacc0bf5e9725c4dbde09d896560085aa7a75e0a
7
- data.tar.gz: 20406f646d0885d2dfbc066825562838a31ad7c4b76ca9b30c0efd6b5218363771e5ad0cee8902b3430bde5f992525a62a91d1ffaac6ed8889383dfff31c1163
6
+ metadata.gz: 95e7d6c19f1c50f01a4a63d0fec9378205956c29b9fb2be22fded7e5fb9c219dde8edfae25b5a3c7f620b01610157b7deb6f2531b79932b66912f7605105a776
7
+ data.tar.gz: b8e4d2e12afb2ea861b6e1136b9f3d263ed5fac7cd700a50969a3ecc556e3599e2200dbde479d99dda264fea753039719509d0f60a76489e98fee771ae7505b2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sandthorn (0.1.0)
4
+ sandthorn (0.1.1)
5
5
  dirty_hashy
6
6
 
7
7
  GEM
@@ -31,11 +31,11 @@ module Sandthorn
31
31
  end
32
32
 
33
33
  def commit *args
34
- increase_current_aggregate_version!
35
- method_name = caller_locations(1,1)[0].label.gsub("block in ", "")
36
34
  aggregate_attribute_deltas = get_delta
37
35
 
38
36
  unless aggregate_attribute_deltas.empty?
37
+ method_name = caller_locations(1,1)[0].label.gsub("block in ", "")
38
+ increase_current_aggregate_version!
39
39
  data = {:method_name => method_name, :method_args => args, :attribute_deltas => aggregate_attribute_deltas}
40
40
  data.merge!({trace: @aggregate_trace_information}) unless @aggregate_trace_information.nil? || @aggregate_trace_information.empty?
41
41
  @aggregate_events << ({:aggregate_version => @aggregate_current_event_version, :event_name => method_name, :event_args => data})
@@ -45,22 +45,22 @@ module Sandthorn
45
45
 
46
46
  alias :record_event :commit
47
47
 
48
- def aggregate_trace args
49
- @aggregate_trace_information = args
50
- yield self
51
- @aggregate_trace_information = nil
52
- end
48
+ # def aggregate_trace args
49
+ # @aggregate_trace_information = args
50
+ # yield self
51
+ # @aggregate_trace_information = nil
52
+ # end
53
53
 
54
54
  module ClassMethods
55
55
 
56
- @@aggregate_trace_information = nil
57
- def aggregate_trace args
58
- @@aggregate_trace_information = args
59
- @aggregate_trace_information = args
60
- yield self
61
- @@aggregate_trace_information = nil
62
- @aggregate_trace_information = nil
63
- end
56
+ # @@aggregate_trace_information = nil
57
+ # def aggregate_trace args
58
+ # @@aggregate_trace_information = args
59
+ # @aggregate_trace_information = args
60
+ # yield self
61
+ # @@aggregate_trace_information = nil
62
+ # @aggregate_trace_information = nil
63
+ # end
64
64
 
65
65
  def all
66
66
  aggregate_id_list = Sandthorn.get_aggregate_list_by_typename(self.name)
@@ -84,13 +84,14 @@ module Sandthorn
84
84
  def new *args
85
85
  aggregate = super
86
86
  aggregate.aggregate_base_initialize
87
+ aggr = aggregate
87
88
 
88
- aggregate.aggregate_trace @@aggregate_trace_information do |aggr|
89
- aggr.aggregate_initialize
90
- aggr.send :set_aggregate_id, Sandthorn.generate_aggregate_id
91
- aggr.send :commit, *args
92
- return aggr
93
- end
89
+ #aggregate.aggregate_trace @@aggregate_trace_information do |aggr|
90
+ aggregate.aggregate_initialize
91
+ aggregate.send :set_aggregate_id, Sandthorn.generate_aggregate_id
92
+ aggregate.send :commit, *args
93
+ aggregate
94
+ #end
94
95
  end
95
96
 
96
97
  def aggregate_build events
@@ -137,6 +138,7 @@ module Sandthorn
137
138
  aggregate.send :set_orginating_aggregate_version!, current_aggregate_version
138
139
  aggregate.send :set_current_aggregate_version!, current_aggregate_version
139
140
  aggregate.send :set_instance_variables!, attributes
141
+ aggregate.send :aggregate_initialize
140
142
  aggregate
141
143
  end
142
144
  end
@@ -150,9 +152,7 @@ module Sandthorn
150
152
  end
151
153
 
152
154
  def extract_relevant_aggregate_instance_variables
153
- instance_variables.select do |i|
154
- i.to_s != "@hashy" && (!i.to_s.start_with?("@aggregate_") || i.to_s == "@aggregate_id")
155
- end
155
+ instance_variables.select { |i| i.to_s=="@aggregate_id" || !i.to_s.start_with?("@aggregate_") }
156
156
  end
157
157
 
158
158
  def set_orginating_aggregate_version! aggregate_version
@@ -169,7 +169,6 @@ module Sandthorn
169
169
 
170
170
  def clear_aggregate_events
171
171
  @aggregate_events = []
172
- @aggregate_attribute_deltas = []
173
172
  end
174
173
 
175
174
  def aggregate_clear_current_event_version!
@@ -10,18 +10,30 @@ module Sandthorn
10
10
  base.extend(Sandthorn::AggregateRoot::Base::ClassMethods)
11
11
  end
12
12
 
13
- def aggregate_initialize
13
+ def aggregate_initialize *args
14
14
  @hashy = ::DirtyHashy.new
15
15
  end
16
16
 
17
+ def set_instance_variables! attribute
18
+ super attribute
19
+
20
+ extract_relevant_aggregate_instance_variables.each do |var|
21
+ next if var.to_s == "@hashy"
22
+ @hashy[var.to_s.delete("@")] = self.instance_variable_get("#{var}")
23
+ end
24
+ @hashy.clean_up!
25
+ end
26
+
17
27
  def get_delta
18
28
  extract_relevant_aggregate_instance_variables.each do |var|
29
+ next if var.to_s == "@hashy"
19
30
  @hashy[var.to_s.delete("@")] = self.instance_variable_get("#{var}")
20
31
  end
21
32
  aggregate_attribute_deltas = []
22
33
  @hashy.changes.each do |attribute|
23
34
  aggregate_attribute_deltas << { :attribute_name => attribute[0], :old_value => attribute[1][0], :new_value => attribute[1][1]}
24
35
  end
36
+ @hashy.clean_up!
25
37
  aggregate_attribute_deltas
26
38
  end
27
39
 
@@ -1,3 +1,3 @@
1
1
  module Sandthorn
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -136,6 +136,36 @@ module Sandthorn
136
136
  expect{DirtyClass.find("666")}.to raise_error
137
137
  end
138
138
  end
139
+
140
+
141
+ end
142
+
143
+ describe "event data" do
144
+
145
+ let(:dirty_obejct) {
146
+ o = DirtyClass.new :name => "old_value"
147
+ o
148
+ }
149
+
150
+ context "old_value should be set" do
151
+
152
+ it "should set the old_value on the event" do
153
+ dirty_obejct.change_name "new_name"
154
+ expect(dirty_obejct.aggregate_events.last[:event_args][:attribute_deltas].first[:old_value]).to eql "old_value"
155
+ end
156
+
157
+ it "should not change aggregate_id" do
158
+ dirty_obejct.change_name "new_name"
159
+ expect(dirty_obejct.aggregate_events.last[:event_args][:attribute_deltas].last[:attribute_name]).not_to eql "aggregate_id"
160
+ end
161
+
162
+ it "should not change sex attribute" do
163
+ dirty_obejct.change_name "new_name"
164
+ dirty_obejct.aggregate_events.each do |event|
165
+ expect(event[:event_name]).not_to eql "change_sex"
166
+ end
167
+ end
168
+ end
139
169
  end
140
170
  end
141
171
  end
@@ -1,152 +1,152 @@
1
- require 'spec_helper'
2
- require 'sandthorn/event_inspector'
3
- require 'sandthorn/aggregate_root_dirty_hashy'
1
+ # require 'spec_helper'
2
+ # require 'sandthorn/event_inspector'
3
+ # require 'sandthorn/aggregate_root_dirty_hashy'
4
4
 
5
- class InspectorAggregate
6
- include Sandthorn::AggregateRoot::DirtyHashy
5
+ # class InspectorAggregate
6
+ # include Sandthorn::AggregateRoot::DirtyHashy
7
7
 
8
- attr_reader :foo_bar
8
+ # attr_reader :foo_bar
9
9
 
10
- def initialize args = {}
11
- @foo_bar = args.fetch(:foo_bar, nil)
12
- end
10
+ # def initialize args = {}
11
+ # @foo_bar = args.fetch(:foo_bar, nil)
12
+ # end
13
13
 
14
- def this_is_an_event args = nil
15
- record_event args
16
- end
17
- def another_event
18
- record_event
19
- end
20
- def new_damaged_item_was_added hello
21
- record_event hello
22
- end
23
- end
14
+ # def this_is_an_event args = nil
15
+ # record_event args
16
+ # end
17
+ # def another_event
18
+ # record_event
19
+ # end
20
+ # def new_damaged_item_was_added hello
21
+ # record_event hello
22
+ # end
23
+ # end
24
24
 
25
- module Sandthorn
26
- describe EventInspector do
27
- let(:aggregate) {InspectorAggregate.new.extend EventInspector}
25
+ # module Sandthorn
26
+ # describe EventInspector do
27
+ # let(:aggregate) {InspectorAggregate.new.extend EventInspector}
28
28
 
29
- context "when using extract_trace_info from an event" do
30
- let(:trace_info) {{user_id: "foo", ip: "bar"}}
31
- let(:subject) do
32
- aggregate.aggregate_trace trace_info do |traced|
33
- traced.this_is_an_event
34
- end
35
- aggregate
36
- end
37
- context "and unsaved aggregate" do
38
- it "should extract exact traceinfo from event" do
39
- all_trace = subject.events_with_trace_info
40
- all_trace.last[:trace].should eql trace_info
41
- end
42
- end
43
- context "and saved aggregate" do
44
- it "should extract exact traceinfo from event" do
45
- subject.save
46
- all_trace = subject.events_with_trace_info
47
- all_trace.last[:trace].should eql trace_info
48
- end
49
- end
50
- end
51
- context "when inspecting non saved events" do
52
- context "with no tracing information" do
53
- let(:subject) { aggregate.this_is_an_event;aggregate }
29
+ # context "when using extract_trace_info from an event" do
30
+ # let(:trace_info) {{user_id: "foo", ip: "bar"}}
31
+ # let(:subject) do
32
+ # aggregate.aggregate_trace trace_info do |traced|
33
+ # traced.this_is_an_event
34
+ # end
35
+ # aggregate
36
+ # end
37
+ # context "and unsaved aggregate" do
38
+ # it "should extract exact traceinfo from event" do
39
+ # all_trace = subject.events_with_trace_info
40
+ # all_trace.last[:trace].should eql trace_info
41
+ # end
42
+ # end
43
+ # context "and saved aggregate" do
44
+ # it "should extract exact traceinfo from event" do
45
+ # subject.save
46
+ # all_trace = subject.events_with_trace_info
47
+ # all_trace.last[:trace].should eql trace_info
48
+ # end
49
+ # end
50
+ # end
51
+ # context "when inspecting non saved events" do
52
+ # context "with no tracing information" do
53
+ # let(:subject) { aggregate.this_is_an_event;aggregate }
54
54
 
55
- it "should have the new event" do
56
- subject.has_event?(:new).should be_true
57
- end
55
+ # it "should have the new event" do
56
+ # subject.has_event?(:new).should be_true
57
+ # end
58
58
 
59
- it "should report true on has_unsaved_event? :this_is_an_event" do
60
- subject.has_unsaved_event?(:this_is_an_event).should be_true
61
- end
62
- it "should report false on has_unsaved_event? :no_event_here" do
63
- subject.has_unsaved_event?(:no_event_here).should be_false
64
- end
65
- end
66
- context "with tracing information" do
67
- let(:subject) do
68
- aggregate.aggregate_trace user_id: 123, ip: "1234" do |traced|
69
- traced.this_is_an_event "my name"
70
- end
71
- aggregate
72
- end
59
+ # it "should report true on has_unsaved_event? :this_is_an_event" do
60
+ # subject.has_unsaved_event?(:this_is_an_event).should be_true
61
+ # end
62
+ # it "should report false on has_unsaved_event? :no_event_here" do
63
+ # subject.has_unsaved_event?(:no_event_here).should be_false
64
+ # end
65
+ # end
66
+ # context "with tracing information" do
67
+ # let(:subject) do
68
+ # aggregate.aggregate_trace user_id: 123, ip: "1234" do |traced|
69
+ # traced.this_is_an_event "my name"
70
+ # end
71
+ # aggregate
72
+ # end
73
73
 
74
- it "should report true on has_unsaved_event? :this_is_an_event" do
75
- subject.has_unsaved_event?(:this_is_an_event, trace: {user_id: 123, ip: "1234"}).should be_true
76
- end
77
- it "should report false on has_unsaved_event? :no_event_here" do
78
- subject.has_unsaved_event?(:this_is_an_event, trace: {user_id: 321}).should be_false
79
- subject.has_unsaved_event?(:this_is_an_event, trace: {another_user_id: 123}).should be_false
80
- end
81
- end
82
- end
83
- context "when inspecting saved events" do
84
- context "with no tracing information" do
85
- let(:subject) { aggregate.this_is_an_event;aggregate.save;aggregate }
74
+ # it "should report true on has_unsaved_event? :this_is_an_event" do
75
+ # subject.has_unsaved_event?(:this_is_an_event, trace: {user_id: 123, ip: "1234"}).should be_true
76
+ # end
77
+ # it "should report false on has_unsaved_event? :no_event_here" do
78
+ # subject.has_unsaved_event?(:this_is_an_event, trace: {user_id: 321}).should be_false
79
+ # subject.has_unsaved_event?(:this_is_an_event, trace: {another_user_id: 123}).should be_false
80
+ # end
81
+ # end
82
+ # end
83
+ # context "when inspecting saved events" do
84
+ # context "with no tracing information" do
85
+ # let(:subject) { aggregate.this_is_an_event;aggregate.save;aggregate }
86
86
 
87
- it "should report true on has_unsaved_event? :this_is_an_event" do
88
- subject.has_saved_event?(:this_is_an_event).should be_true
89
- end
90
- it "should report false on has_unsaved_event? :no_event_here" do
91
- subject.has_saved_event?(:no_event_here).should be_false
92
- end
93
- end
94
- context "with tracing information" do
95
- let(:subject) do
96
- aggregate.aggregate_trace user_id: 123, ip: "1234" do |traced|
97
- traced.this_is_an_event "my name"
98
- end
99
- aggregate.save
100
- aggregate
101
- end
87
+ # it "should report true on has_unsaved_event? :this_is_an_event" do
88
+ # subject.has_saved_event?(:this_is_an_event).should be_true
89
+ # end
90
+ # it "should report false on has_unsaved_event? :no_event_here" do
91
+ # subject.has_saved_event?(:no_event_here).should be_false
92
+ # end
93
+ # end
94
+ # context "with tracing information" do
95
+ # let(:subject) do
96
+ # aggregate.aggregate_trace user_id: 123, ip: "1234" do |traced|
97
+ # traced.this_is_an_event "my name"
98
+ # end
99
+ # aggregate.save
100
+ # aggregate
101
+ # end
102
102
 
103
- it "should report true on has_unsaved_event? :this_is_an_event" do
104
- subject.has_saved_event?(:this_is_an_event, trace: {user_id: 123, ip: "1234"}).should be_true
105
- end
106
- it "should report false on has_unsaved_event? :no_event_here" do
107
- subject.has_saved_event?(:this_is_an_event, trace: {user_id: 321}).should be_false
108
- subject.has_saved_event?(:this_is_an_event, trace: {another_user_id: 123}).should be_false
109
- end
110
- it "should be able to check complex trace" do
111
- subject.aggregate_trace client_ip: "10", user_id: "123" do |trace|
112
- trace.new_damaged_item_was_added "foobar"
113
- trace.save
114
- end
115
- subject.has_saved_event?(:new_damaged_item_was_added, trace: {user_id: "123", client_ip: "10"})
116
- end
117
- end
118
- end
119
- context "when inspecting any events" do
120
- context "with no tracing information" do
121
- let(:subject) { aggregate.this_is_an_event;aggregate.save;aggregate.another_event;aggregate }
103
+ # it "should report true on has_unsaved_event? :this_is_an_event" do
104
+ # subject.has_saved_event?(:this_is_an_event, trace: {user_id: 123, ip: "1234"}).should be_true
105
+ # end
106
+ # it "should report false on has_unsaved_event? :no_event_here" do
107
+ # subject.has_saved_event?(:this_is_an_event, trace: {user_id: 321}).should be_false
108
+ # subject.has_saved_event?(:this_is_an_event, trace: {another_user_id: 123}).should be_false
109
+ # end
110
+ # it "should be able to check complex trace" do
111
+ # subject.aggregate_trace client_ip: "10", user_id: "123" do |trace|
112
+ # trace.new_damaged_item_was_added "foobar"
113
+ # trace.save
114
+ # end
115
+ # subject.has_saved_event?(:new_damaged_item_was_added, trace: {user_id: "123", client_ip: "10"})
116
+ # end
117
+ # end
118
+ # end
119
+ # context "when inspecting any events" do
120
+ # context "with no tracing information" do
121
+ # let(:subject) { aggregate.this_is_an_event;aggregate.save;aggregate.another_event;aggregate }
122
122
 
123
- it "should report true on has_unsaved_event? :this_is_an_event" do
124
- subject.has_event?(:this_is_an_event).should be_true
125
- subject.has_event?(:another_event).should be_true
126
- end
127
- it "should report false on has_unsaved_event? :no_event_here" do
128
- subject.has_event?(:no_event_here).should be_false
129
- end
130
- end
131
- context "with tracing information" do
132
- let(:subject) do
133
- aggregate.aggregate_trace user_id: 123, ip: "1234" do |traced|
134
- traced.this_is_an_event "my name"
135
- traced.save
136
- traced.another_event
137
- end
138
- aggregate
139
- end
123
+ # it "should report true on has_unsaved_event? :this_is_an_event" do
124
+ # subject.has_event?(:this_is_an_event).should be_true
125
+ # subject.has_event?(:another_event).should be_true
126
+ # end
127
+ # it "should report false on has_unsaved_event? :no_event_here" do
128
+ # subject.has_event?(:no_event_here).should be_false
129
+ # end
130
+ # end
131
+ # context "with tracing information" do
132
+ # let(:subject) do
133
+ # aggregate.aggregate_trace user_id: 123, ip: "1234" do |traced|
134
+ # traced.this_is_an_event "my name"
135
+ # traced.save
136
+ # traced.another_event
137
+ # end
138
+ # aggregate
139
+ # end
140
140
 
141
- it "should report true on has_unsaved_event? :this_is_an_event" do
142
- subject.has_event?(:this_is_an_event, trace: {user_id: 123, ip: "1234"}).should be_true
143
- subject.has_event?(:another_event, trace: {user_id: 123, ip: "1234"}).should be_true
144
- end
145
- it "should report false on has_unsaved_event? :no_event_here" do
146
- subject.has_event?(:this_is_an_event, trace: {user_id: 321}).should be_false
147
- subject.has_event?(:another_event, trace: {ip: "123"}).should be_false
148
- end
149
- end
150
- end
151
- end
152
- end
141
+ # it "should report true on has_unsaved_event? :this_is_an_event" do
142
+ # subject.has_event?(:this_is_an_event, trace: {user_id: 123, ip: "1234"}).should be_true
143
+ # subject.has_event?(:another_event, trace: {user_id: 123, ip: "1234"}).should be_true
144
+ # end
145
+ # it "should report false on has_unsaved_event? :no_event_here" do
146
+ # subject.has_event?(:this_is_an_event, trace: {user_id: 321}).should be_false
147
+ # subject.has_event?(:another_event, trace: {ip: "123"}).should be_false
148
+ # end
149
+ # end
150
+ # end
151
+ # end
152
+ # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandthorn
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
  - Lars Krantz
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-31 00:00:00.000000000 Z
12
+ date: 2014-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler