active_event 0.5.0.rc4 → 0.5.0.rc5

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: d695d82e04ff4395d4ed6ed08e40315f63b90722
4
- data.tar.gz: 05043c74ef8487177bbb09848a2a13cb9ad69b87
3
+ metadata.gz: df8dd99b28d2b809d9a56eb4aa46a9b00ae908af
4
+ data.tar.gz: f1b4c218923220b3bd50d40c9e4b81f7aa127d1e
5
5
  SHA512:
6
- metadata.gz: f183b8a4e89b5a32ec86a0764a75d83d945756fdfec065554bd9df51489372204f799292dc134136abf5fadc56c74cd3b87c07fd6dfe3f466ed1063eed728d76
7
- data.tar.gz: 636526f08010a506cda3e64155710ab0c9109086cc4d736f2feb37a0bf4a8d1aa6003db56b314f3af8f8cf6e4cb9e62024f1dca1c73b4f3048e18014ce744aa8
6
+ metadata.gz: 183cece38086fe744d48efa6c9517cb0f3b0bf673890bd0ed3ac04e66c620fc957d412af0eac9c4fc3a94bc7d72c6a32a08cd805c03e087fd206b5678d20f7e6
7
+ data.tar.gz: 4dc0205111f8f487551f9b4b2be50edaaf8cf57ad6bb9555987c0134281ce877fe72d96c6874688b1ad7e321cb3c9f0e12b50bcb7800d8185523b415d1426c76
@@ -19,17 +19,8 @@ module ActiveEvent
19
19
  include ActiveEvent::Support::AttrSetter
20
20
  include ActiveModel::Validations
21
21
 
22
- def is_valid_do(&block)
23
- if valid?
24
- block.call
25
- else
26
- false
27
- end
28
- rescue Exception => e
29
- LOGGER.error "Validation failed for #{self.class.name}"
30
- LOGGER.error e.message
31
- LOGGER.error e.backtrace.join("\n")
32
- false
22
+ def is_valid_do
23
+ yield if valid?
33
24
  end
34
25
 
35
26
  module ClassMethods
@@ -1,42 +1,53 @@
1
- require 'singleton'
2
- require 'drb/drb'
3
-
4
- module ActiveEvent
5
- module Domain
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- include Singleton # singleton is not a concern - include directly into class
10
- end
11
-
12
- def initialize(*args)
13
- super
14
- # DRb.start_service # should not be necessary
15
- self.server = DRbObject.new_with_uri self.class.server_uri
16
- end
17
-
18
- def run_command(command)
19
- server.run_command command
20
- end
21
-
22
- private
23
-
24
- attr_accessor :server
25
-
26
- module ClassMethods
27
- def run_command(command)
28
- self.instance.run_command command
29
- end
30
-
31
- attr_accessor :server_uri
32
-
33
- def self.extended(base)
34
- base.server_uri = 'druby://127.0.0.1:8787'
35
- end
36
-
37
- def set_config(protocol = 'druby', host = 'localhost', port = 8787)
38
- self.server_uri = "#{protocol}://#{host}:#{port}"
39
- end
40
- end
41
- end
42
- end
1
+ require 'singleton'
2
+ require 'drb/drb'
3
+
4
+ module ActiveEvent
5
+ class DomainExceptionCapture < StandardError
6
+ end
7
+
8
+ class DomainException < StandardError
9
+ # prevent better errors from tracing this exception
10
+ def __better_errors_bindings_stack; [] end
11
+ end
12
+
13
+ module Domain
14
+ extend ActiveSupport::Concern
15
+
16
+ included do
17
+ include Singleton # singleton is not a concern - include directly into class
18
+ end
19
+
20
+ def initialize(*args)
21
+ super
22
+ # DRb.start_service # should not be necessary
23
+ self.server = DRbObject.new_with_uri self.class.server_uri
24
+ end
25
+
26
+ def run_command(command)
27
+ command.valid? && server.run_command(command)
28
+ rescue DomainExceptionCapture => e
29
+ message, backtrace = JSON.parse(e.message)
30
+ raise DomainException, message, backtrace
31
+ end
32
+
33
+ private
34
+
35
+ attr_accessor :server
36
+
37
+ module ClassMethods
38
+ def run_command(command)
39
+ self.instance.run_command command
40
+ end
41
+
42
+ attr_accessor :server_uri
43
+
44
+ def self.extended(base)
45
+ base.server_uri = 'druby://127.0.0.1:8787'
46
+ end
47
+
48
+ def set_config(protocol = 'druby', host = 'localhost', port = 8787)
49
+ self.server_uri = "#{protocol}://#{host}:#{port}"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -2,11 +2,22 @@ require 'singleton'
2
2
  require 'bunny'
3
3
 
4
4
  module ActiveEvent
5
+ class ProjectionException < StandardError
6
+ # prevent better errors from tracing this exception
7
+ def __better_errors_bindings_stack; [] end
8
+ end
9
+
5
10
  class EventSourceServer
6
11
  include Singleton
7
12
 
8
- def self.after_event_projection(event_id, projection, &block)
9
- instance.after_event_projection(event_id, projection, &block)
13
+ class << self
14
+ def after_event_projection(event_id, projection, &block)
15
+ instance.after_event_projection(event_id, projection, &block)
16
+ end
17
+
18
+ def projection_status(projection)
19
+ instance.projection_status(projection)
20
+ end
10
21
  end
11
22
 
12
23
  def after_event_projection(event_id, projection)
@@ -21,10 +32,18 @@ module ActiveEvent
21
32
  projection_status.waiters[event_id].delete cv
22
33
  end
23
34
  end
35
+ raise ProjectionException, projection_status.error, projection_status.backtrace if projection_status.error
24
36
  end
25
37
  yield
26
38
  end
27
39
 
40
+ def projection_status(projection)
41
+ mutex.synchronize do
42
+ projection_status = status[projection]
43
+ raise ProjectionException, projection_status.error, projection_status.backtrace if projection_status.error
44
+ end
45
+ end
46
+
28
47
  private
29
48
 
30
49
  class Status
@@ -6,15 +6,21 @@ module ActiveEvent
6
6
  @io = io
7
7
  end
8
8
 
9
- def write(object, options = {})
10
- options.each do |k, v|
11
- @io.write "#{k}: #{v}\n"
9
+ def event(event, data = nil, options = {})
10
+ self.data options.merge(event: event, data: JSON.dump(data))
11
+ end
12
+
13
+ def data(data)
14
+ data.each_pair do |key, value|
15
+ (value+"\n").split("\n", -1)[0..-2].each do |v|
16
+ @io.write "#{key}: #{v}\n"
17
+ end
12
18
  end
13
- @io.write "data: #{JSON.dump(object)}\n\n"
19
+ @io.write "\n"
14
20
  end
15
21
 
16
22
  def close
17
23
  @io.close
18
24
  end
19
25
  end
20
- end
26
+ end
@@ -0,0 +1,24 @@
1
+ # a hash with limited size
2
+ class HashBuffer < Array
3
+ attr_accessor :max_size
4
+
5
+ def initialize(max_size, *args, &block)
6
+ super(*args, &block)
7
+ self.max_size = max_size
8
+ end
9
+
10
+ def max_size=(new_size)
11
+ delete keys.first while new_size < size
12
+ self.max_size = new_size
13
+ end
14
+
15
+ private
16
+
17
+ attr_accessor entries
18
+
19
+ def []=(key, value)
20
+ delete keys.first if max_size && size == max_size
21
+ super
22
+ end
23
+ alias :push :<<
24
+ end
@@ -0,0 +1,20 @@
1
+ # simple ring buffer
2
+ class RingBuffer < Array
3
+ attr_accessor :max_size
4
+
5
+ def initialize(max_size, *args, &block)
6
+ super(*args, &block)
7
+ self.max_size = max_size
8
+ end
9
+
10
+ def max_size=(new_size)
11
+ replace first(new_size) if new_size < size
12
+ self.max_size = new_size
13
+ end
14
+
15
+ def <<(item)
16
+ shift if max_size && size == max_size
17
+ super
18
+ end
19
+ alias :push :<<
20
+ end
@@ -1,7 +1,7 @@
1
1
  module ActiveEvent
2
2
  # Returns the version of the currently loaded ActiveEvent as a Gem::Version
3
3
  def self.version
4
- Gem::Version.new '0.5.0.rc4'
4
+ Gem::Version.new '0.5.0.rc5'
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
@@ -13,6 +13,7 @@ describe ActiveEvent::Domain do
13
13
 
14
14
  it 'sends command over instance' do
15
15
  expect(DRbObject).to receive(:new_with_uri).with(TestDomain.server_uri).and_return(@drb_object)
16
+ expect(@command).to receive(:valid?).and_return(true)
16
17
  expect(@drb_object).to receive(:run_command).with(@command)
17
18
  TestDomain.run_command(@command)
18
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.rc4
4
+ version: 0.5.0.rc5
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-04-22 00:00:00.000000000 Z
11
+ date: 2014-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -147,9 +147,12 @@ executables: []
147
147
  extensions: []
148
148
  extra_rdoc_files: []
149
149
  files:
150
+ - MIT-LICENSE
151
+ - README.md
150
152
  - app/models/active_event/event.rb
151
153
  - app/models/active_event/event_repository.rb
152
154
  - db/migrate/00_create_domain_events.rb
155
+ - lib/active_event.rb
153
156
  - lib/active_event/autoload.rb
154
157
  - lib/active_event/command.rb
155
158
  - lib/active_event/domain.rb
@@ -162,13 +165,12 @@ files:
162
165
  - lib/active_event/support/attr_setter.rb
163
166
  - lib/active_event/support/autoload.rb
164
167
  - lib/active_event/support/autoloader.rb
168
+ - lib/active_event/support/hash_buffer.rb
165
169
  - lib/active_event/support/multi_logger.rb
170
+ - lib/active_event/support/ring_buffer.rb
166
171
  - lib/active_event/validations.rb
167
172
  - lib/active_event/validations_registry.rb
168
173
  - lib/active_event/version.rb
169
- - lib/active_event.rb
170
- - README.md
171
- - MIT-LICENSE
172
174
  - spec/factories/event_factory.rb
173
175
  - spec/lib/command_spec.rb
174
176
  - spec/lib/domain_spec.rb
@@ -200,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
202
  version: 1.3.1
201
203
  requirements: []
202
204
  rubyforge_project:
203
- rubygems_version: 2.1.11
205
+ rubygems_version: 2.2.2
204
206
  signing_key:
205
207
  specification_version: 4
206
208
  summary: Commands, Events and Validations for Rails Disco