active_event 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 +9 -9
- data/app/models/active_event/event.rb +15 -15
- data/app/models/active_event/event_repository.rb +11 -11
- data/db/migrate/00_create_domain_events.rb +9 -9
- data/lib/active_event/autoload.rb +11 -9
- data/lib/active_event/command.rb +35 -39
- data/lib/active_event/domain.rb +4 -2
- data/lib/active_event/event_server.rb +72 -76
- data/lib/active_event/event_source_server.rb +149 -127
- data/lib/active_event/event_type.rb +29 -28
- data/lib/active_event/replay_server.rb +94 -98
- data/lib/active_event/sse.rb +26 -26
- data/lib/active_event/support/attr_initializer.rb +76 -74
- data/lib/active_event/support/attr_setter.rb +31 -29
- data/lib/active_event/support/autoload.rb +46 -44
- data/lib/active_event/support/autoloader.rb +41 -38
- data/lib/active_event/support/multi_logger.rb +31 -28
- data/lib/active_event/validations.rb +68 -68
- data/lib/active_event/validations_registry.rb +18 -18
- data/lib/active_event/version.rb +1 -1
- data/spec/factories/event_factory.rb +9 -9
- data/spec/lib/command_spec.rb +14 -14
- data/spec/lib/domain_spec.rb +21 -21
- data/spec/lib/event_server_spec.rb +29 -29
- data/spec/lib/event_type_spec.rb +38 -38
- data/spec/lib/replay_server_spec.rb +71 -68
- data/spec/lib/support/attr_initializer_spec.rb +55 -55
- data/spec/lib/support/attr_setter_spec.rb +61 -61
- data/spec/models/event_spec.rb +20 -20
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +40 -38
- metadata +2 -4
- data/lib/active_event/support/hash_buffer.rb +0 -24
- data/lib/active_event/support/ring_buffer.rb +0 -20
@@ -1,29 +1,31 @@
|
|
1
|
-
module ActiveEvent
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
1
|
+
module ActiveEvent
|
2
|
+
module Support
|
3
|
+
# Allows to initialize and set attributes with a hash
|
4
|
+
#
|
5
|
+
# example:
|
6
|
+
# class RgbColor
|
7
|
+
# include ActiveEvent::AttrSetter
|
8
|
+
# attributes :r, :g, :b
|
9
|
+
# end
|
10
|
+
# green = RgbColor.new r: 250, g: 20, b: 20
|
11
|
+
# green.r = 255
|
12
|
+
module AttrSetter
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
include ActiveEvent::Support::AttrInitializer
|
15
|
+
|
16
|
+
# override to skip the freezing!
|
17
|
+
def init_attributes(attributes)
|
18
|
+
self.attributes = attributes.symbolize_keys
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def attributes(*args)
|
23
|
+
super
|
24
|
+
args.each do |attr|
|
25
|
+
define_method "#{attr}=", ->(value) { attributes[attr] = value }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,44 +1,46 @@
|
|
1
|
-
module ActiveEvent
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
watchable_dirs
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
1
|
+
module ActiveEvent
|
2
|
+
module Support
|
3
|
+
module Autoload
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
module ClassMethods
|
6
|
+
def app_path=(path)
|
7
|
+
self.dir_path = path
|
8
|
+
Autoloader.load_from dirs
|
9
|
+
end
|
10
|
+
|
11
|
+
def reload_module(module_name)
|
12
|
+
path = [parent.name, module_name.to_s].join('::').underscore
|
13
|
+
Autoloader.reload module_name, path
|
14
|
+
end
|
15
|
+
|
16
|
+
def reload
|
17
|
+
Autoloader.reload_from dirs
|
18
|
+
end
|
19
|
+
|
20
|
+
def watchable_dirs
|
21
|
+
watchable_dirs = {}
|
22
|
+
dir_names.each do |dir_name|
|
23
|
+
watchable_dirs[dir_name] = [:rb]
|
24
|
+
end
|
25
|
+
watchable_dirs
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def dir_names
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
|
34
|
+
def dir_path=(path)
|
35
|
+
@dirs = dir_names.map do |dir_name|
|
36
|
+
"#{path}/#{dir_name}/**/*.rb"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def dirs
|
41
|
+
@dirs ||= ''
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,38 +1,41 @@
|
|
1
|
-
module ActiveEvent
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
1
|
+
module ActiveEvent
|
2
|
+
module Support
|
3
|
+
module Autoloader
|
4
|
+
def self.load_from(dirs)
|
5
|
+
Dir[*dirs].each do |file|
|
6
|
+
require file
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.reload_from(dirs)
|
11
|
+
Dir[*dirs].each do |path|
|
12
|
+
reload get_module_name(path), path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.reload(name, path)
|
17
|
+
const_name, namespace_name = name.to_s.split('::').reverse
|
18
|
+
if namespace_name.nil?
|
19
|
+
Object.send(:remove_const, const_name) if Object.const_defined?(const_name)
|
20
|
+
else
|
21
|
+
namespace = const_get(namespace_name)
|
22
|
+
namespace.send(:remove_const, const_name) if namespace.const_defined?(const_name)
|
23
|
+
end
|
24
|
+
$LOADED_FEATURES.delete_if { |s| s.include?(path) }
|
25
|
+
require path
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def self.get_module_name(path)
|
31
|
+
segments = path.split('/')
|
32
|
+
seg = if 1 == (segments.length - 2) - (segments.index('app') || segments.index('domain')) # no namespace
|
33
|
+
segments.last.split('.').first
|
34
|
+
else
|
35
|
+
[segments[-2], segments.last.split('.').first].join('/')
|
36
|
+
end
|
37
|
+
seg.camelcase.to_sym
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,28 +1,31 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module ActiveEvent
|
4
|
+
module Support
|
5
|
+
class MultiLogger
|
6
|
+
[:info, :debug, :error, :fatal, :warn, :unknown].each do |action|
|
7
|
+
define_method action do |msg|
|
8
|
+
@loggers.each do |logger|
|
9
|
+
logger.send(action, msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(progname = nil, formatter = nil)
|
15
|
+
@loggers = []
|
16
|
+
@loggers << Logger.new(STDOUT)
|
17
|
+
@loggers << Logger.new('log/disco.log')
|
18
|
+
@loggers.each do |logger|
|
19
|
+
logger.progname = progname if progname.present?
|
20
|
+
logger.formatter = if formatter.present?
|
21
|
+
formatter
|
22
|
+
else
|
23
|
+
proc do |severity, datetime, pprogname, msg|
|
24
|
+
"#{datetime}: [#{pprogname}][#{severity}]: #{msg}\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
module ActiveEvent
|
2
|
-
module Validations
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
include ActiveModel::Validations
|
5
|
-
|
6
|
-
def self.included(base)
|
7
|
-
super
|
8
|
-
base.extend const_get('RegisterMethods')
|
9
|
-
end
|
10
|
-
|
11
|
-
module RegisterMethods
|
12
|
-
def skip_validate(*args)
|
13
|
-
options = args.extract_options!
|
14
|
-
if options.key?(:on)
|
15
|
-
options = options.dup
|
16
|
-
options[:if] = Array(options[:if])
|
17
|
-
options[:if].unshift("validation_context == :#{options[:on]}")
|
18
|
-
end
|
19
|
-
args << options
|
20
|
-
skip_callback(:validate, *args)
|
21
|
-
end
|
22
|
-
|
23
|
-
def skip_validates(*attributes)
|
24
|
-
defaults = attributes.extract_options!.dup
|
25
|
-
validations = defaults.slice!(*_validates_default_keys)
|
26
|
-
|
27
|
-
return if attributes.empty?
|
28
|
-
return if validations.empty?
|
29
|
-
|
30
|
-
defaults[:attributes] = attributes
|
31
|
-
|
32
|
-
validations.each do |key, options|
|
33
|
-
next unless options
|
34
|
-
key = "#{key.to_s.camelize}Validator"
|
35
|
-
|
36
|
-
begin
|
37
|
-
validator = key.include?('::') ? key.constantize : const_get(key)
|
38
|
-
rescue NameError
|
39
|
-
raise ArgumentError, "Unknown validator: '#{key}'"
|
40
|
-
end
|
41
|
-
|
42
|
-
skip_validates_with(validator, defaults.merge(_parse_validates_options(options)))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def skip_validates_with(*args)
|
47
|
-
options = args.extract_options!
|
48
|
-
args.each do |klass|
|
49
|
-
validator = klass.new(options)
|
50
|
-
|
51
|
-
if validator.respond_to?(:attributes) && !validator.attributes.empty?
|
52
|
-
validator.attributes.each do |attribute|
|
53
|
-
_validators[attribute.to_sym].reject! { |x| x.instance_of? klass } if _validators.key? attribute.to_sym
|
54
|
-
end
|
55
|
-
else
|
56
|
-
_validators[nil].reject! { |x| x.instance_of? klass }
|
57
|
-
end
|
58
|
-
|
59
|
-
skip_validate(validator, options)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def validation_target(target)
|
64
|
-
ValidationsRegistry.register self, target
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
module ActiveEvent
|
2
|
+
module Validations
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
super
|
8
|
+
base.extend const_get('RegisterMethods')
|
9
|
+
end
|
10
|
+
|
11
|
+
module RegisterMethods
|
12
|
+
def skip_validate(*args)
|
13
|
+
options = args.extract_options!
|
14
|
+
if options.key?(:on)
|
15
|
+
options = options.dup
|
16
|
+
options[:if] = Array(options[:if])
|
17
|
+
options[:if].unshift("validation_context == :#{options[:on]}")
|
18
|
+
end
|
19
|
+
args << options
|
20
|
+
skip_callback(:validate, *args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def skip_validates(*attributes)
|
24
|
+
defaults = attributes.extract_options!.dup
|
25
|
+
validations = defaults.slice!(*_validates_default_keys)
|
26
|
+
|
27
|
+
return if attributes.empty?
|
28
|
+
return if validations.empty?
|
29
|
+
|
30
|
+
defaults[:attributes] = attributes
|
31
|
+
|
32
|
+
validations.each do |key, options|
|
33
|
+
next unless options
|
34
|
+
key = "#{key.to_s.camelize}Validator"
|
35
|
+
|
36
|
+
begin
|
37
|
+
validator = key.include?('::') ? key.constantize : const_get(key)
|
38
|
+
rescue NameError
|
39
|
+
raise ArgumentError, "Unknown validator: '#{key}'"
|
40
|
+
end
|
41
|
+
|
42
|
+
skip_validates_with(validator, defaults.merge(_parse_validates_options(options)))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def skip_validates_with(*args)
|
47
|
+
options = args.extract_options!
|
48
|
+
args.each do |klass|
|
49
|
+
validator = klass.new(options)
|
50
|
+
|
51
|
+
if validator.respond_to?(:attributes) && !validator.attributes.empty?
|
52
|
+
validator.attributes.each do |attribute|
|
53
|
+
_validators[attribute.to_sym].reject! { |x| x.instance_of? klass } if _validators.key? attribute.to_sym
|
54
|
+
end
|
55
|
+
else
|
56
|
+
_validators[nil].reject! { |x| x.instance_of? klass }
|
57
|
+
end
|
58
|
+
|
59
|
+
skip_validate(validator, options)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def validation_target(target)
|
64
|
+
ValidationsRegistry.register self, target
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
module ActiveEvent
|
2
|
-
class ValidationsRegistry
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
cattr_accessor :bindings
|
16
|
-
self.bindings = []
|
17
|
-
end
|
18
|
-
end
|
1
|
+
module ActiveEvent
|
2
|
+
class ValidationsRegistry
|
3
|
+
def self.register(validations, target)
|
4
|
+
bindings << {validation: validations, target: target}
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.build
|
8
|
+
bindings.freeze.each do |binding|
|
9
|
+
Object.const_get(binding[:target].to_s).send :include, binding[:validation]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
cattr_accessor :bindings
|
16
|
+
self.bindings = []
|
17
|
+
end
|
18
|
+
end
|