active_event 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +19 -19
  3. data/README.md +9 -9
  4. data/app/models/active_event/event.rb +15 -15
  5. data/app/models/active_event/event_repository.rb +11 -11
  6. data/db/migrate/00_create_domain_events.rb +9 -9
  7. data/lib/active_event/autoload.rb +11 -9
  8. data/lib/active_event/command.rb +35 -39
  9. data/lib/active_event/domain.rb +4 -2
  10. data/lib/active_event/event_server.rb +72 -76
  11. data/lib/active_event/event_source_server.rb +149 -127
  12. data/lib/active_event/event_type.rb +29 -28
  13. data/lib/active_event/replay_server.rb +94 -98
  14. data/lib/active_event/sse.rb +26 -26
  15. data/lib/active_event/support/attr_initializer.rb +76 -74
  16. data/lib/active_event/support/attr_setter.rb +31 -29
  17. data/lib/active_event/support/autoload.rb +46 -44
  18. data/lib/active_event/support/autoloader.rb +41 -38
  19. data/lib/active_event/support/multi_logger.rb +31 -28
  20. data/lib/active_event/validations.rb +68 -68
  21. data/lib/active_event/validations_registry.rb +18 -18
  22. data/lib/active_event/version.rb +1 -1
  23. data/spec/factories/event_factory.rb +9 -9
  24. data/spec/lib/command_spec.rb +14 -14
  25. data/spec/lib/domain_spec.rb +21 -21
  26. data/spec/lib/event_server_spec.rb +29 -29
  27. data/spec/lib/event_type_spec.rb +38 -38
  28. data/spec/lib/replay_server_spec.rb +71 -68
  29. data/spec/lib/support/attr_initializer_spec.rb +55 -55
  30. data/spec/lib/support/attr_setter_spec.rb +61 -61
  31. data/spec/models/event_spec.rb +20 -20
  32. data/spec/spec_helper.rb +1 -1
  33. data/spec/support/active_record.rb +40 -38
  34. metadata +2 -4
  35. data/lib/active_event/support/hash_buffer.rb +0 -24
  36. data/lib/active_event/support/ring_buffer.rb +0 -20
@@ -1,29 +1,31 @@
1
- module ActiveEvent::Support
2
- # Allows to initialize and set attributes with a hash
3
- #
4
- # example:
5
- # class RgbColor
6
- # include ActiveEvent::AttrSetter
7
- # attributes :r, :g, :b
8
- # end
9
- # green = RgbColor.new r: 250, g: 20, b: 20
10
- # green.r = 255
11
- module AttrSetter
12
- extend ActiveSupport::Concern
13
- include ActiveEvent::Support::AttrInitializer
14
-
15
- # override to skip the freezing!
16
- def init_attributes(attributes)
17
- self.attributes = attributes.symbolize_keys
18
- end
19
-
20
- module ClassMethods
21
- def attributes(*args)
22
- super
23
- args.each do |attr|
24
- define_method "#{attr}=", lambda { |value| attributes[attr] = value }
25
- end
26
- end
27
- end
28
- end
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::Support
2
- module Autoload
3
- extend ActiveSupport::Concern
4
- module ClassMethods
5
- def app_path=(path)
6
- set_dirs path
7
- Autoloader.load_from dirs
8
- end
9
-
10
- def reload_module(module_name)
11
- path = [parent.name, module_name.to_s].join('::').underscore
12
- Autoloader.reload module_name, path
13
- end
14
-
15
- def reload
16
- Autoloader.reload_from dirs
17
- end
18
-
19
- def watchable_dirs
20
- watchable_dirs = {}
21
- dir_names.each do |dir_name|
22
- watchable_dirs[dir_name] = [:rb]
23
- end
24
- watchable_dirs
25
- end
26
-
27
- private
28
-
29
- def dir_names
30
- []
31
- end
32
-
33
- def set_dirs(path)
34
- @dirs = dir_names.map do |dir_name|
35
- "#{path}/#{dir_name}/**/*.rb"
36
- end
37
- end
38
-
39
- def dirs
40
- @dirs ||= ''
41
- end
42
- end
43
- end
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::Support
2
- module Autoloader
3
- def self.load_from(dirs)
4
- Dir[*dirs].each do |file|
5
- require file
6
- end
7
- end
8
-
9
- def self.reload_from(dirs)
10
- Dir[*dirs].each do |path|
11
- reload get_module_name(path), path
12
- end
13
- end
14
-
15
- def self.reload(name, path)
16
- const_name, namespace_name = name.to_s.split('::').reverse
17
- if namespace_name.nil?
18
- Object.send(:remove_const, const_name) if Object.const_defined?(const_name)
19
- else
20
- namespace = const_get(namespace_name)
21
- namespace.send(:remove_const, const_name) if namespace.const_defined?(const_name)
22
- end
23
- $".delete_if { |s| s.include?(path) }
24
- require path
25
- end
26
-
27
- private
28
- def self.get_module_name(path)
29
- segments = path.split('/')
30
- seg = if 1 == (segments.length - 2) - (segments.index('app') || segments.index('domain')) #no namespace
31
- segments.last.split('.').first
32
- else
33
- [segments[-2], segments.last.split('.').first].join('/')
34
- end
35
- seg.camelcase.to_sym
36
- end
37
- end
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
- module ActiveEvent::Support
3
- class MultiLogger
4
- [:info, :debug, :error, :fatal, :warn, :unknown, ].each do |action|
5
- define_method action do |msg|
6
- @loggers.each do |logger|
7
- logger.send(action, msg)
8
- end
9
- end
10
- end
11
-
12
- def initialize(progname = nil, formatter = nil)
13
- @loggers = []
14
- @loggers << Logger.new(STDOUT)
15
- @loggers << Logger.new("log/disco.log")
16
- @loggers.each do |logger|
17
- logger.progname = progname if progname.present?
18
- logger.formatter = if formatter.present?
19
- formatter
20
- else
21
- proc do |severity, datetime, progname, msg|
22
- "#{datetime}: [#{progname}][#{severity}]: #{msg}\n"
23
- end
24
- end
25
- end
26
- end
27
- end
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
- def self.register(validations, target)
5
- self.bindings << {validation: validations, target: target}
6
- end
7
-
8
- def self.build
9
- self.bindings.freeze.each do |binding|
10
- Object.const_get(binding[:target].to_s).send :include, binding[:validation]
11
- end
12
- end
13
-
14
- private
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