active_domain 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +19 -19
- data/README.md +8 -8
- data/app/models/active_domain/event.rb +10 -10
- data/app/models/active_domain/event_repository.rb +16 -17
- data/app/models/active_domain/unique_command_id.rb +5 -5
- data/app/models/active_domain/unique_command_id_repository.rb +24 -23
- data/db/migrate/02_create_unique_command_ids.rb +9 -9
- data/lib/active_domain.rb +19 -19
- data/lib/active_domain/autoload.rb +11 -9
- data/lib/active_domain/command_processor.rb +41 -41
- data/lib/active_domain/command_routes.rb +1 -1
- data/lib/active_domain/projection.rb +9 -10
- data/lib/active_domain/projection_registry.rb +48 -48
- data/lib/active_domain/server.rb +81 -82
- data/lib/active_domain/version.rb +1 -1
- data/spec/lib/command_processor_spec.rb +30 -30
- data/spec/lib/projection_registry_spec.rb +26 -25
- data/spec/lib/projection_spec.rb +12 -12
- data/spec/spec_helper.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4300944cb388d1c759829594b8e8aadca5808f40
|
4
|
+
data.tar.gz: 0a879f57bfee653fc04f2c7d4f5153fececf4f9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef42ad447b93a6e3402fecd9cb5488f0d4d60ca59cf75a242fd1ff87e3c0d33cef46d766c01fcae20fa5b074422997291a04c37690e0667422bdcd6c3f0fec57
|
7
|
+
data.tar.gz: 43f8be9d7dc0f2048e4cd93ed4f42471a9a4ca28bfc7bed6a98877a41aeeb6d7adc99491fe8f476d1c3469f4f6a325624db599a4aac870ba349adec3b9f5ba5b
|
data/MIT-LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2013 Andreas Reischuck
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
1
|
+
Copyright (c) 2013 Andreas Reischuck
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# Active Domain
|
2
|
-
|
3
|
-
A framework that allows to write a domain server, that processes commands and creates events.
|
4
|
-
|
5
|
-
You should have exactly one domain server for your Rails Disco applications.
|
6
|
-
The domain runs in a domain specific database environment. This helps to make sure no other process interferes with the domain.
|
7
|
-
|
8
|
-
Have a look at the [rails-disco](https://github.com/hicknhack-software/rails-disco/wiki) documentation on Github for more details.
|
1
|
+
# Active Domain
|
2
|
+
|
3
|
+
A framework that allows to write a domain server, that processes commands and creates events.
|
4
|
+
|
5
|
+
You should have exactly one domain server for your Rails Disco applications.
|
6
|
+
The domain runs in a domain specific database environment. This helps to make sure no other process interferes with the domain.
|
7
|
+
|
8
|
+
Have a look at the [rails-disco](https://github.com/hicknhack-software/rails-disco/wiki) documentation on Github for more details.
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module ActiveDomain
|
2
|
-
class Event < ActiveEvent::Event
|
3
|
-
self.table_name = 'domain_events'
|
4
|
-
|
5
|
-
# allow write inside the domain
|
6
|
-
def readonly?
|
7
|
-
@readonly
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module ActiveDomain
|
2
|
+
class Event < ActiveEvent::Event
|
3
|
+
self.table_name = 'domain_events'
|
4
|
+
|
5
|
+
# allow write inside the domain
|
6
|
+
def readonly?
|
7
|
+
@readonly
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,17 +1,16 @@
|
|
1
|
-
module ActiveDomain
|
2
|
-
class EventRepository
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
1
|
+
module ActiveDomain
|
2
|
+
class EventRepository
|
3
|
+
def self.ordered
|
4
|
+
ActiveDomain::Event.order(:id)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.after_id(id)
|
8
|
+
ordered.where ActiveDomain::Event.arel_table['id'].gt(id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.store(event)
|
12
|
+
stored_event = ActiveDomain::Event.create!(event: event.class.name, data: event.to_hash)
|
13
|
+
event.add_store_infos id: stored_event.id, created_at: stored_event.created_at
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module ActiveDomain
|
2
|
-
class UniqueCommandId < ActiveRecord::Base
|
3
|
-
self.table_name = 'unique_command_ids'
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module ActiveDomain
|
2
|
+
class UniqueCommandId < ActiveRecord::Base
|
3
|
+
self.table_name = 'unique_command_ids'
|
4
|
+
end
|
5
|
+
end
|
@@ -1,23 +1,24 @@
|
|
1
|
-
module ActiveDomain
|
2
|
-
class UniqueCommandIdRepository
|
3
|
-
def self.new_for(command_name)
|
4
|
-
@@commands[command_name] ||= create_or_get(command_name)
|
5
|
-
create_new @@commands[command_name]
|
6
|
-
end
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
command.last_id
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
1
|
+
module ActiveDomain
|
2
|
+
class UniqueCommandIdRepository
|
3
|
+
def self.new_for(command_name)
|
4
|
+
@@commands[command_name] ||= create_or_get(command_name)
|
5
|
+
create_new @@commands[command_name]
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create_or_get(command_name)
|
14
|
+
UniqueCommandId.find_or_create_by! command: command_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create_new(command)
|
18
|
+
command.update! last_id: command.last_id + 1
|
19
|
+
command.last_id
|
20
|
+
end
|
21
|
+
|
22
|
+
@@commands = {}
|
23
|
+
end
|
24
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class CreateUniqueCommandIds < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :unique_command_ids do |t|
|
4
|
-
t.string :command
|
5
|
-
t.integer :last_id, default: 0
|
6
|
-
end
|
7
|
-
add_index :unique_command_ids, :command, unique: true
|
8
|
-
end
|
9
|
-
end
|
1
|
+
class CreateUniqueCommandIds < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :unique_command_ids do |t|
|
4
|
+
t.string :command
|
5
|
+
t.integer :last_id, default: 0
|
6
|
+
end
|
7
|
+
add_index :unique_command_ids, :command, unique: true
|
8
|
+
end
|
9
|
+
end
|
data/lib/active_domain.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'active_event'
|
2
|
-
require 'active_support/core_ext'
|
3
|
-
require 'active_domain/version'
|
4
|
-
|
5
|
-
module ActiveDomain
|
6
|
-
extend ActiveSupport::Autoload
|
7
|
-
|
8
|
-
autoload :Autoload
|
9
|
-
autoload :CommandProcessor
|
10
|
-
autoload :CommandRoutes
|
11
|
-
autoload :Projection
|
12
|
-
autoload :ProjectionRegistry
|
13
|
-
autoload :Server
|
14
|
-
|
15
|
-
autoload :Event, (File.expand_path '../../app/models/active_domain/event', __FILE__)
|
16
|
-
autoload :EventRepository, (File.expand_path '../../app/models/active_domain/event_repository',__FILE__)
|
17
|
-
autoload :UniqueCommandId, (File.expand_path '../../app/models/active_domain/unique_command_id', __FILE__)
|
18
|
-
autoload :UniqueCommandIdRepository, (File.expand_path '../../app/models/active_domain/unique_command_id_repository',__FILE__)
|
19
|
-
end
|
1
|
+
require 'active_event'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'active_domain/version'
|
4
|
+
|
5
|
+
module ActiveDomain
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :Autoload
|
9
|
+
autoload :CommandProcessor
|
10
|
+
autoload :CommandRoutes
|
11
|
+
autoload :Projection
|
12
|
+
autoload :ProjectionRegistry
|
13
|
+
autoload :Server
|
14
|
+
|
15
|
+
autoload :Event, (File.expand_path '../../app/models/active_domain/event', __FILE__)
|
16
|
+
autoload :EventRepository, (File.expand_path '../../app/models/active_domain/event_repository', __FILE__)
|
17
|
+
autoload :UniqueCommandId, (File.expand_path '../../app/models/active_domain/unique_command_id', __FILE__)
|
18
|
+
autoload :UniqueCommandIdRepository, (File.expand_path '../../app/models/active_domain/unique_command_id_repository', __FILE__)
|
19
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
module ActiveDomain
|
2
|
-
module Autoload
|
3
|
-
include ActiveEvent::Support::Autoload
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
1
|
+
module ActiveDomain
|
2
|
+
module Autoload
|
3
|
+
include ActiveEvent::Support::Autoload
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def self.dir_names
|
8
|
+
%w(domain/command_processors domain/validations domain/models domain/projections)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
require 'drb/drb'
|
2
|
-
|
3
|
-
module ActiveDomain
|
4
|
-
module CommandProcessor
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
include DRb::DRbUndumped
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
protected
|
10
|
-
|
11
|
-
def process(clazz, method_name = nil, &block)
|
12
|
-
method_name ||= "process#{clazz.name.split('::').last}"
|
13
|
-
define_method(method_name, &block)
|
14
|
-
CommandRoutes.route clazz, self, method_name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
def event(event)
|
21
|
-
store event
|
22
|
-
publish event
|
23
|
-
invoke event
|
24
|
-
event.store_infos[:id]
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def invoke(event)
|
30
|
-
ProjectionRegistry.invoke event
|
31
|
-
end
|
32
|
-
|
33
|
-
def store(event)
|
34
|
-
EventRepository.store event
|
35
|
-
end
|
36
|
-
|
37
|
-
def publish(event)
|
38
|
-
ActiveEvent::EventServer.publish event
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require 'drb/drb'
|
2
|
+
|
3
|
+
module ActiveDomain
|
4
|
+
module CommandProcessor
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
include DRb::DRbUndumped
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
protected
|
10
|
+
|
11
|
+
def process(clazz, method_name = nil, &block)
|
12
|
+
method_name ||= "process#{clazz.name.split('::').last}"
|
13
|
+
define_method(method_name, &block)
|
14
|
+
CommandRoutes.route clazz, self, method_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def event(event)
|
21
|
+
store event
|
22
|
+
publish event
|
23
|
+
invoke event
|
24
|
+
event.store_infos[:id]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def invoke(event)
|
30
|
+
ProjectionRegistry.invoke event
|
31
|
+
end
|
32
|
+
|
33
|
+
def store(event)
|
34
|
+
EventRepository.store event
|
35
|
+
end
|
36
|
+
|
37
|
+
def publish(event)
|
38
|
+
ActiveEvent::EventServer.publish event
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -14,7 +14,7 @@ module ActiveDomain
|
|
14
14
|
RELOADER.execute_if_updated
|
15
15
|
processor, method = @@routes[command.class]
|
16
16
|
processor_instance(processor).method(method).call(command)
|
17
|
-
rescue
|
17
|
+
rescue => e
|
18
18
|
LOGGER.error e.message
|
19
19
|
LOGGER.error e.backtrace.join("\n")
|
20
20
|
raise ActiveEvent::DomainExceptionCapture, ["#{e.class.name}: #{e.message}", e.backtrace].to_json, e.backtrace
|
@@ -1,10 +1,9 @@
|
|
1
|
-
module ActiveDomain
|
2
|
-
module Projection
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
ProjectionRegistry
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
end
|
1
|
+
module ActiveDomain
|
2
|
+
module Projection
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
ProjectionRegistry.register(self)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
|
-
module ActiveDomain
|
4
|
-
class TooManyArgumentsError < StandardError
|
5
|
-
end
|
6
|
-
|
7
|
-
class ProjectionRegistry
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
def self.register(event_handler)
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.invoke(event)
|
15
|
-
instance.invoke event
|
16
|
-
end
|
17
|
-
|
18
|
-
def invoke(event)
|
19
|
-
event_type = event.class.name.to_s
|
20
|
-
return unless handlers.
|
21
|
-
handlers[event_type].each do |handler_method|
|
22
|
-
handler_method.owner.new.send handler_method.name, event
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
cattr_accessor :registry
|
29
|
-
attr_accessor :handlers
|
30
|
-
|
31
|
-
def initialize
|
32
|
-
self.handlers = Hash.new do |hash, key|
|
33
|
-
hash[key] = []
|
34
|
-
end
|
35
|
-
self.class.registry.freeze.each do |handler|
|
36
|
-
handler.public_instance_methods(false).each do |method_name|
|
37
|
-
method = handler.instance_method method_name
|
38
|
-
event_type = (method_name.to_s.split('__')*'/').camelcase
|
39
|
-
|
40
|
-
handlers[event_type] << method
|
41
|
-
end
|
42
|
-
end
|
43
|
-
handlers.freeze
|
44
|
-
end
|
45
|
-
|
46
|
-
self.registry = []
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module ActiveDomain
|
4
|
+
class TooManyArgumentsError < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class ProjectionRegistry
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def self.register(event_handler)
|
11
|
+
registry << event_handler
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.invoke(event)
|
15
|
+
instance.invoke event
|
16
|
+
end
|
17
|
+
|
18
|
+
def invoke(event)
|
19
|
+
event_type = event.class.name.to_s
|
20
|
+
return unless handlers.key? event_type
|
21
|
+
handlers[event_type].each do |handler_method|
|
22
|
+
handler_method.owner.new.send handler_method.name, event
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
cattr_accessor :registry
|
29
|
+
attr_accessor :handlers
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
self.handlers = Hash.new do |hash, key|
|
33
|
+
hash[key] = []
|
34
|
+
end
|
35
|
+
self.class.registry.freeze.each do |handler|
|
36
|
+
handler.public_instance_methods(false).each do |method_name|
|
37
|
+
method = handler.instance_method method_name
|
38
|
+
event_type = (method_name.to_s.split('__') * '/').camelcase
|
39
|
+
fail TooManyArgumentsError if 1 != method.arity
|
40
|
+
handlers[event_type] << method
|
41
|
+
end
|
42
|
+
end
|
43
|
+
handlers.freeze
|
44
|
+
end
|
45
|
+
|
46
|
+
self.registry = []
|
47
|
+
end
|
48
|
+
end
|
data/lib/active_domain/server.rb
CHANGED
@@ -1,82 +1,81 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'drb/drb'
|
3
|
-
|
4
|
-
module ActiveDomain
|
5
|
-
class Server
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
drb_uri
|
19
|
-
DRb.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
LOGGER.error e.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
cattr_accessor :
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
attr_writer :
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
options
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
1
|
+
require 'active_record'
|
2
|
+
require 'drb/drb'
|
3
|
+
|
4
|
+
module ActiveDomain
|
5
|
+
class Server
|
6
|
+
def self.run(options = nil)
|
7
|
+
new(options).run
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(new_options = nil)
|
11
|
+
self.options = new_options.deep_symbolize_keys! unless new_options.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
ActiveRecord::Base.establish_connection options[:domain_database]
|
16
|
+
ActiveEvent::EventServer.start options
|
17
|
+
drb_uri = URI::Generic.build(options[:drb_server]).to_s
|
18
|
+
DRb.start_service(drb_uri, domain, options.fetch(:drb_config, {}))
|
19
|
+
DRb.thread.join
|
20
|
+
rescue Interrupt
|
21
|
+
LOGGER.info 'Catching Interrupt'
|
22
|
+
rescue => e
|
23
|
+
LOGGER.error e.message
|
24
|
+
LOGGER.error e.backtrace.join("\n")
|
25
|
+
raise e
|
26
|
+
end
|
27
|
+
|
28
|
+
def env
|
29
|
+
@env = ENV['DOMAIN_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
30
|
+
end
|
31
|
+
|
32
|
+
def options
|
33
|
+
@options ||= parse_options(ARGV)
|
34
|
+
end
|
35
|
+
|
36
|
+
def domain
|
37
|
+
@domain ||= ActiveDomain::CommandRoutes.new
|
38
|
+
end
|
39
|
+
|
40
|
+
cattr_accessor :base_path
|
41
|
+
cattr_accessor :config_file
|
42
|
+
|
43
|
+
def config_file
|
44
|
+
self.class.config_file || File.expand_path('config/disco.yml', base_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
attr_writer :options
|
50
|
+
attr_writer :domain
|
51
|
+
|
52
|
+
def default_options
|
53
|
+
{
|
54
|
+
drb_server: {
|
55
|
+
scheme: 'druby',
|
56
|
+
hostname: '127.0.0.1',
|
57
|
+
port: 8787,
|
58
|
+
},
|
59
|
+
drb_config: {
|
60
|
+
verbose: true,
|
61
|
+
},
|
62
|
+
domain_database: {
|
63
|
+
adapter: 'sqlite3',
|
64
|
+
database: File.expand_path('db/domain.sqlite3', base_path),
|
65
|
+
},
|
66
|
+
event_connection: {
|
67
|
+
scheme: 'amqp',
|
68
|
+
userinfo: nil,
|
69
|
+
host: '127.0.0.1',
|
70
|
+
port: 9797,
|
71
|
+
},
|
72
|
+
event_exchange: 'events',
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_options(_args)
|
77
|
+
options = default_options
|
78
|
+
options.merge! YAML.load_file(config_file)[env].deep_symbolize_keys! unless config_file.blank?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe ActiveDomain::CommandProcessor do
|
4
|
-
class TestDummy
|
5
|
-
include ActiveEvent::EventType
|
6
|
-
end
|
7
|
-
class TestDummyProcessor
|
8
|
-
include ActiveDomain::CommandProcessor
|
9
|
-
|
10
|
-
process TestDummy do |cmd|
|
11
|
-
event cmd
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'class helper' do
|
16
|
-
it 'define event process' do
|
17
|
-
TestDummyProcessor.instance_method(:processTestDummy).
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'instance' do
|
22
|
-
it 'allows event method' do
|
23
|
-
magic_number = TestDummy.new
|
24
|
-
expect(ActiveDomain::ProjectionRegistry).to receive(:invoke).with(magic_number)
|
25
|
-
expect(ActiveDomain::EventRepository).to receive(:store).with(magic_number)
|
26
|
-
expect(ActiveEvent::EventServer).to receive(:publish).with(magic_number)
|
27
|
-
TestDummyProcessor.new.processTestDummy magic_number
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe ActiveDomain::CommandProcessor do
|
4
|
+
class TestDummy
|
5
|
+
include ActiveEvent::EventType
|
6
|
+
end
|
7
|
+
class TestDummyProcessor
|
8
|
+
include ActiveDomain::CommandProcessor
|
9
|
+
|
10
|
+
process TestDummy do |cmd|
|
11
|
+
event cmd
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'class helper' do
|
16
|
+
it 'define event process' do
|
17
|
+
expect(TestDummyProcessor.instance_method(:processTestDummy)).to be
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'instance' do
|
22
|
+
it 'allows event method' do
|
23
|
+
magic_number = TestDummy.new
|
24
|
+
expect(ActiveDomain::ProjectionRegistry).to receive(:invoke).with(magic_number)
|
25
|
+
expect(ActiveDomain::EventRepository).to receive(:store).with(magic_number)
|
26
|
+
expect(ActiveEvent::EventServer).to receive(:publish).with(magic_number)
|
27
|
+
TestDummyProcessor.new.processTestDummy magic_number
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,25 +1,26 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe ActiveDomain::ProjectionRegistry do
|
4
|
-
class TestEvent
|
5
|
-
end
|
6
|
-
class TestProjection
|
7
|
-
def test_event(
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe ActiveDomain::ProjectionRegistry do
|
4
|
+
class TestEvent
|
5
|
+
end
|
6
|
+
class TestProjection
|
7
|
+
def test_event(_event)
|
8
|
+
end
|
9
|
+
|
10
|
+
def dummy_event(_event)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
before :all do
|
14
|
+
ActiveDomain::ProjectionRegistry.register(TestProjection)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'initializes' do
|
18
|
+
expect(ActiveDomain::ProjectionRegistry.instance).to be
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'invokes event handlers' do
|
22
|
+
event = TestEvent.new
|
23
|
+
expect_any_instance_of(TestProjection).to receive(:test_event).with(event)
|
24
|
+
ActiveDomain::ProjectionRegistry.invoke(event)
|
25
|
+
end
|
26
|
+
end
|
data/spec/lib/projection_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe ActiveDomain::Projection do
|
4
|
-
it 'should register automatically' do
|
5
|
-
expect(ActiveDomain::ProjectionRegistry).to receive(:register) do |arg|
|
6
|
-
arg.name.to_sym.
|
7
|
-
end
|
8
|
-
class TestProjection
|
9
|
-
include ActiveDomain::Projection
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe ActiveDomain::Projection do
|
4
|
+
it 'should register automatically' do
|
5
|
+
expect(ActiveDomain::ProjectionRegistry).to receive(:register) do |arg|
|
6
|
+
expect(arg.name.to_sym).to eq(:TestProjection)
|
7
|
+
end
|
8
|
+
class TestProjection
|
9
|
+
include ActiveDomain::Projection
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HicknHack Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_event
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.5.
|
19
|
+
version: 0.5.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.5.
|
26
|
+
version: 0.5.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|