command_post 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/lib/command_post/db/postgresql.sql +10 -2
- data/lib/command_post/event_sourcing/aggregate.rb +18 -4
- data/lib/command_post/persistence/persistence.rb +71 -7
- data/lib/command_post/version.rb +1 -1
- data/spec/command_post/identity/identity_lookup_value_aggregate_id_spec.rb +3 -0
- data/spec/command_post/identity/identity_lookup_value_checksum_spec.rb +3 -0
- data/spec/command_post/identity/identity_lookup_value_field_spec.rb +3 -0
- data/spec/command_post/persistence/data_validation_spec.rb +3 -0
- data/spec/command_post/persistence/querying_spec.rb +11 -0
- data/spec/command_post/persistence/schema_validation_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e017af18ee1497964678d7476ff8923328d115f1
|
4
|
+
data.tar.gz: b1e3e62ddb8333b3ae2af14cb119f03613211f6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 678251e4d7116fd089a225ab83cd9a4eddcf513305624a998ec68eb1ec8c1578a7a890b492cb1b29a80ee866c379fd98d850f2a658dde249e2b374b03226bab7
|
7
|
+
data.tar.gz: 4a2490595d96353e8e674e50a47ce93e40c6b612fe97c434f34311caa7c5b7a2abd547b35c48ccb95009c3e4255ca55f5c62d8651382a100bd5c57c8bf1ba9d7
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,40 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
+
coderay (1.0.9)
|
5
|
+
columnize (0.3.6)
|
6
|
+
debugger (1.6.1)
|
7
|
+
columnize (>= 0.3.1)
|
8
|
+
debugger-linecache (~> 1.2.0)
|
9
|
+
debugger-ruby_core_source (~> 1.2.3)
|
10
|
+
debugger-linecache (1.2.0)
|
11
|
+
debugger-ruby_core_source (1.2.3)
|
12
|
+
faker (1.2.0)
|
13
|
+
i18n (~> 0.5)
|
4
14
|
ffi (1.9.0)
|
5
15
|
ffi (1.9.0-x86-mingw32)
|
16
|
+
i18n (0.6.5)
|
6
17
|
listen (1.2.2)
|
7
18
|
rb-fsevent (>= 0.9.3)
|
8
19
|
rb-inotify (>= 0.9)
|
9
20
|
rb-kqueue (>= 0.2)
|
21
|
+
method_source (0.8.2)
|
10
22
|
pg (0.16.0)
|
11
23
|
pg (0.16.0-x86-mingw32)
|
24
|
+
pry (0.9.12.2)
|
25
|
+
coderay (~> 1.0.5)
|
26
|
+
method_source (~> 0.8)
|
27
|
+
slop (~> 3.4)
|
28
|
+
pry-debugger (0.2.2)
|
29
|
+
debugger (~> 1.3)
|
30
|
+
pry (~> 0.9.10)
|
12
31
|
rb-fsevent (0.9.3)
|
13
32
|
rb-inotify (0.9.0)
|
14
33
|
ffi (>= 0.5.0)
|
15
34
|
rb-kqueue (0.2.0)
|
16
35
|
ffi (>= 0.5.0)
|
17
36
|
sequel (4.0.0)
|
37
|
+
slop (3.4.6)
|
18
38
|
starting_blocks (0.0.31)
|
19
39
|
listen (>= 1.0)
|
20
40
|
|
@@ -23,6 +43,9 @@ PLATFORMS
|
|
23
43
|
x86-mingw32
|
24
44
|
|
25
45
|
DEPENDENCIES
|
46
|
+
faker
|
26
47
|
pg
|
48
|
+
pry
|
49
|
+
pry-debugger
|
27
50
|
sequel
|
28
51
|
starting_blocks
|
@@ -35,11 +35,19 @@ create index aggregate_lookup_idx on aggregates(aggregate_lookup_value);
|
|
35
35
|
|
36
36
|
|
37
37
|
|
38
|
-
|
39
38
|
|
39
|
+
create table aggregate_index (
|
40
|
+
aggregate_id bigint not null,
|
41
|
+
index_field varchar(100) not null,
|
42
|
+
index_value varchar(100) not null,
|
43
|
+
) ;
|
40
44
|
|
45
|
+
create index aggregate_index on aggregates(aggregate_lookup_value);
|
46
|
+
|
41
47
|
CREATE SEQUENCE aggregate START 1;
|
42
48
|
|
49
|
+
|
43
50
|
CREATE SEQUENCE transaction START 1;
|
44
51
|
|
45
|
-
CREATE SEQUENCE misc START 1;
|
52
|
+
CREATE SEQUENCE misc START 1;
|
53
|
+
|
@@ -15,9 +15,8 @@ module CommandPost
|
|
15
15
|
class Aggregate
|
16
16
|
|
17
17
|
@@prep_stmt_insert ||= $DB[:aggregates].prepare(:insert, :insert_aggregate, :aggregate_id => :$aggregate_id, :aggregate_type => :$aggregate_type, :content => :$content, :aggregate_lookup_value => :$aggregate_lookup_value )
|
18
|
-
@@
|
19
|
-
|
20
|
-
|
18
|
+
@@prep_stmt_insert_index ||= $DB[:aggregate_indexes].prepare(:insert, :insert_aggregate_indexes, :aggregate_id => :$aggregate_id, :index_field => :$index_field, :index_value => :$index_value )
|
19
|
+
|
21
20
|
|
22
21
|
def self.replace object, aggregate_lookup_value
|
23
22
|
|
@@ -29,9 +28,24 @@ module CommandPost
|
|
29
28
|
|
30
29
|
|
31
30
|
if (version) == 1
|
32
|
-
@@prep_stmt_insert.call(:aggregate_id => aggregate_id, :aggregate_type => aggregate_type
|
31
|
+
@@prep_stmt_insert.call(:aggregate_id => aggregate_id.to_i, :aggregate_type => aggregate_type , :content => content, :aggregate_lookup_value => aggregate_lookup_value )
|
32
|
+
|
33
|
+
object = Aggregate.get_by_aggregate_id Object.const_get(aggregate_type), aggregate_id
|
34
|
+
|
35
|
+
object.index_fields.each do |field|
|
36
|
+
index_value = object.send field
|
37
|
+
index_field = "#{object.class.to_s}.#{field.to_s}"
|
38
|
+
@@prep_stmt_insert_index.call(:aggregate_id => aggregate_id, :index_field => index_field, :index_value => index_value )
|
39
|
+
end
|
33
40
|
else
|
34
41
|
$DB["UPDATE aggregates set content = ?, aggregate_lookup_value = ? where aggregate_id = ?", content, aggregate_lookup_value, aggregate_id ].update
|
42
|
+
object = Aggregate.get_by_aggregate_id Object.const_get(aggregate_type), aggregate_id
|
43
|
+
@@prep_stmt_insert.call(:aggregate_id => aggregate_id.to_i, :aggregate_type => aggregate_type , :content => content, :aggregate_lookup_value => aggregate_lookup_value )
|
44
|
+
object.index_fields.each do |field|
|
45
|
+
index_value = object.send field
|
46
|
+
index_field = "#{object.class.to_s}.#{field.to_s}"
|
47
|
+
$DB["UPDATE aggregate_indexes set index_value = ? where aggregate_id = ? and index_field = ?", index_value, aggregate_id.to_i, index_field ].update
|
48
|
+
end
|
35
49
|
end
|
36
50
|
end
|
37
51
|
|
@@ -7,6 +7,9 @@ require_relative './data_validation.rb'
|
|
7
7
|
require_relative './auto_load.rb'
|
8
8
|
require_relative '../command/command.rb'
|
9
9
|
|
10
|
+
require 'pry'
|
11
|
+
require 'pry-debugger'
|
12
|
+
|
10
13
|
module CommandPost
|
11
14
|
|
12
15
|
class Persistence
|
@@ -17,9 +20,11 @@ module CommandPost
|
|
17
20
|
def initialize
|
18
21
|
|
19
22
|
@@fields ||= Hash.new
|
23
|
+
@@indexes ||= Hash.new
|
20
24
|
@aggregate_info_set = false
|
21
25
|
@data = Hash.new
|
22
26
|
self.class.init_schema self.class.schema
|
27
|
+
self.class.init_indexes self.class.indexes
|
23
28
|
Command.auto_generate self.class
|
24
29
|
end
|
25
30
|
|
@@ -29,6 +34,11 @@ module CommandPost
|
|
29
34
|
@@fields[self.class]
|
30
35
|
end
|
31
36
|
|
37
|
+
def index_fields
|
38
|
+
@@indexes[self.class]
|
39
|
+
end
|
40
|
+
|
41
|
+
|
32
42
|
|
33
43
|
def set_data data_hash
|
34
44
|
@data = data_hash
|
@@ -57,12 +67,55 @@ module CommandPost
|
|
57
67
|
end
|
58
68
|
|
59
69
|
|
60
|
-
def
|
70
|
+
def self.stringify_values values
|
71
|
+
|
72
|
+
values.collect{|x| "'#{x}'"}.join(',')
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.get_index_sql name, values
|
77
|
+
|
78
|
+
"SELECT aggregate_id FROM aggregate_indexes WHERE index_field = '#{name}' AND index_value in (#{self.stringify_values(values)}) "
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def self.get_ids_for_index index_name, *args
|
83
|
+
|
84
|
+
values = args[0][0]
|
85
|
+
name = "#{self.to_s}.#{index_name.to_s.sub(/_in$/,'')}"
|
86
|
+
sql = get_index_sql name, values
|
87
|
+
results = Array.new
|
88
|
+
$DB.fetch(sql) do |row|
|
89
|
+
results << row[:aggregate_id]
|
90
|
+
end
|
91
|
+
|
92
|
+
results
|
93
|
+
|
94
|
+
end
|
95
|
+
|
61
96
|
|
97
|
+
def self.method_missing nm, *args , &block
|
62
98
|
name = nm.to_s
|
63
|
-
|
99
|
+
search_index = name.gsub(/_in/,'').to_sym
|
100
|
+
if (name.end_with?('_in') && self.indexes.include?(search_index))
|
101
|
+
ids = self.get_ids_for_index nm, args
|
102
|
+
return ids
|
103
|
+
else
|
104
|
+
begin
|
105
|
+
super
|
106
|
+
rescue Exception => e
|
107
|
+
raise e.message
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
64
112
|
|
113
|
+
def method_missing(nm, *args)
|
65
114
|
|
115
|
+
name = nm.to_s
|
116
|
+
error_msg = "SCHEMA ERROR: #{name} is not a defined attribute of or index on '#{self.class.to_s}'"
|
117
|
+
|
118
|
+
if name.end_with?('=') == false
|
66
119
|
if @data.keys.include? nm
|
67
120
|
get_data nm
|
68
121
|
else
|
@@ -71,13 +124,14 @@ module CommandPost
|
|
71
124
|
else
|
72
125
|
begin
|
73
126
|
super
|
74
|
-
rescue
|
75
|
-
|
127
|
+
rescue Exception => e
|
128
|
+
raise error_msg
|
76
129
|
end
|
77
130
|
end
|
78
131
|
end
|
79
132
|
else
|
80
133
|
nm = name.gsub(/\=/,'').to_sym
|
134
|
+
raise error_msg unless schema_fields.keys.include?(nm)
|
81
135
|
@data[nm] = args.first
|
82
136
|
end
|
83
137
|
end
|
@@ -109,6 +163,16 @@ module CommandPost
|
|
109
163
|
@@fields[self] ||= fields
|
110
164
|
end
|
111
165
|
|
166
|
+
def self.init_indexes index_fields
|
167
|
+
@@indexes ||= Hash.new
|
168
|
+
# index_error_messages = IndexValidation.validate_indexes(index_fields)
|
169
|
+
# if index_error_messages.length > 0
|
170
|
+
# raise ArgumentError, "The declared indexes for #{self} had the following error(s): #{pp index_error_messages}"
|
171
|
+
# end
|
172
|
+
@@indexes[self] ||= index_fields
|
173
|
+
end
|
174
|
+
|
175
|
+
|
112
176
|
|
113
177
|
def self.load_from_hash the_class, string_hash
|
114
178
|
|
@@ -127,9 +191,9 @@ module CommandPost
|
|
127
191
|
object.set_data data_hash
|
128
192
|
object.populate_auto_load_fields #unless self.bypass_auto_load == true
|
129
193
|
object.populate_local_persistent_objects
|
130
|
-
if (the_class.included_modules.include?(CommandPost::Identity) == true)
|
131
|
-
|
132
|
-
end
|
194
|
+
# if (the_class.included_modules.include?(CommandPost::Identity) == true)
|
195
|
+
# object.set_aggregate_lookup_value
|
196
|
+
# end
|
133
197
|
object
|
134
198
|
end
|
135
199
|
|
data/lib/command_post/version.rb
CHANGED
@@ -19,6 +19,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../command_post/require')
|
|
19
19
|
fields[ :last_name ] = { :required => true, :type => String, :location => :local }
|
20
20
|
fields
|
21
21
|
end
|
22
|
+
def self.indexes
|
23
|
+
[]
|
24
|
+
end
|
22
25
|
end
|
23
26
|
some_class = SomeClass01.new
|
24
27
|
some_class.class.must_be_same_as SomeClass01
|
@@ -45,6 +48,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../command_post/require')
|
|
45
48
|
fields[ 'last_name' ] = { :required => true, :type => String, :location => :local }
|
46
49
|
fields
|
47
50
|
end
|
51
|
+
def self.indexes
|
52
|
+
[]
|
53
|
+
end
|
48
54
|
end
|
49
55
|
|
50
56
|
assert_raises(ArgumentError) { some_class = SomeClass02.new }
|
@@ -94,6 +100,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../command_post/require')
|
|
94
100
|
fields[ :last_name ] = { :required => true, :type => String, :location => :local }
|
95
101
|
fields
|
96
102
|
end
|
103
|
+
def self.indexes
|
104
|
+
[]
|
105
|
+
end
|
97
106
|
end
|
98
107
|
|
99
108
|
assert_raises(ArgumentError) { some_class = SomeClass04.new }
|
@@ -119,6 +128,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../command_post/require')
|
|
119
128
|
fields[ :last_name ] = { :required => true, :type => String, :location => :local }
|
120
129
|
fields
|
121
130
|
end
|
131
|
+
def self.indexes
|
132
|
+
[]
|
133
|
+
end
|
122
134
|
end
|
123
135
|
|
124
136
|
assert_raises(ArgumentError) { some_class = SomeClass05.new }
|
@@ -144,6 +156,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../command_post/require')
|
|
144
156
|
fields[ :last_name ] = { :required => true, :type => String, :location => :local }
|
145
157
|
fields
|
146
158
|
end
|
159
|
+
def self.indexes
|
160
|
+
[]
|
161
|
+
end
|
147
162
|
end
|
148
163
|
|
149
164
|
assert_raises(ArgumentError) { some_class = SomeClass06.new }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Meirow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- spec/command_post/identity/identity_lookup_value_field_spec.rb
|
74
74
|
- spec/command_post/persistence/data_validation_spec.rb
|
75
75
|
- spec/command_post/persistence/nested_remote_spec.rb
|
76
|
+
- spec/command_post/persistence/querying_spec.rb
|
76
77
|
- spec/command_post/persistence/schema_validation_spec.rb
|
77
78
|
- spec/command_post/require.rb
|
78
79
|
- spec/spec_helper.rb
|
@@ -107,6 +108,7 @@ test_files:
|
|
107
108
|
- spec/command_post/identity/identity_lookup_value_field_spec.rb
|
108
109
|
- spec/command_post/persistence/data_validation_spec.rb
|
109
110
|
- spec/command_post/persistence/nested_remote_spec.rb
|
111
|
+
- spec/command_post/persistence/querying_spec.rb
|
110
112
|
- spec/command_post/persistence/schema_validation_spec.rb
|
111
113
|
- spec/command_post/require.rb
|
112
114
|
- spec/spec_helper.rb
|