ruby_event_store 0.17.0 → 0.18.0

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: 35a6c9c18570cf1b5a722848d18ba266468fac23
4
- data.tar.gz: b828a65276522ddd1466e520707d9988dcada1a7
3
+ metadata.gz: '001956750bd7d68e07b581f7b1c663f8de9e6240'
4
+ data.tar.gz: 39d8a11eea0f103619e5663b28c2b0cc0bbc041b
5
5
  SHA512:
6
- metadata.gz: 53e14871a197ed39bbd7e29703c30f3ff1cffb38c831d2997e3473a853500b0ef340ab54a26c47c4482eaf84d8c77f384132fc5414931b7360c91cbae26bcf04
7
- data.tar.gz: 1d78107bb4ab8c6c2a45c6ead73c76b3bf771ed1ab62ae9c41e5a4d9ce056faaafaa97ab722513bcb2dc1105dda3535c3ad1af98ce8579d775e25b6b42861360
6
+ metadata.gz: cb16c704a08ff8c48ab5451d3d5e6273d43dddcee0d40bd9962e41284f53fd91af49b63b0d8b52557df718269878fba246978e380de01be52b2cf5e3d8dbf14c
7
+ data.tar.gz: 901ac8b836a0ef6c3ae35e41cba6141d8090e6777b844a552fe20cee06467e35d9dffd80697769d88fe0d4c173bc47733e30b3f5d429baecf004df1189a75910
data/Makefile CHANGED
@@ -1,25 +1,29 @@
1
- install-bundler: ## Install gem dependencies
1
+ GEM_VERSION = `cat ../RES_VERSION`
2
+
3
+ install: ## Install gem dependencies
2
4
  @echo "Installing gem dependencies"
3
5
  @bundle install
4
6
 
5
- install: install-bundler ## Prepare current development environment
6
-
7
7
  test: ## Run tests
8
8
  @echo "Running basic tests - beware: this won't guarantee build pass"
9
9
  @bundle exec rspec
10
10
 
11
11
  mutate: test ## Run mutation tests
12
12
  @echo "Running mutation tests - only 100% free mutation will be accepted"
13
- @bundle exec mutant --include lib --require ruby_event_store --use rspec --ignore-subject "RubyEventStore.const_missing" "RubyEventStore*"
13
+ @bundle exec mutant --include lib --require ruby_event_store --use rspec "RubyEventStore*" \
14
+ --ignore-subject "RubyEventStore.const_missing"
14
15
 
15
- release:
16
- @rake build
17
- @rake release:rubygem_push
16
+ build:
17
+ @gem build -V ruby_event_store.gemspec
18
+ @mkdir -p pkg/
19
+ @mv ruby_event_store-$(GEM_VERSION).gem pkg/
18
20
 
19
- .PHONY: help
21
+ release: build
22
+ @gem push pkg/ruby_event_store-$(GEM_VERSION).gem
20
23
 
21
24
  help:
22
25
  @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
23
26
 
27
+ .PHONY: help
24
28
  .DEFAULT_GOAL := help
25
29
 
@@ -64,13 +64,13 @@ module RubyEventStore
64
64
  end
65
65
 
66
66
  def subscribe(subscriber, event_types, &proc)
67
- event_broker.add_subscriber(subscriber, event_types).tap do |unsub|
67
+ event_broker.add_subscriber(subscriber_or_proxy(subscriber), event_types).tap do |unsub|
68
68
  handle_subscribe(unsub, &proc)
69
69
  end
70
70
  end
71
71
 
72
72
  def subscribe_to_all_events(subscriber, &proc)
73
- event_broker.add_global_subscriber(subscriber).tap do |unsub|
73
+ event_broker.add_global_subscriber(subscriber_or_proxy(subscriber)).tap do |unsub|
74
74
  handle_subscribe(unsub, &proc)
75
75
  end
76
76
  end
@@ -78,6 +78,10 @@ module RubyEventStore
78
78
  private
79
79
  attr_reader :repository, :page_size, :event_broker, :metadata_proc, :clock
80
80
 
81
+ def subscriber_or_proxy(subscriber)
82
+ subscriber.instance_of?(Class) ? event_broker.proxy_for(subscriber) : subscriber
83
+ end
84
+
81
85
  def enrich_event_metadata(event)
82
86
  metadata = event.metadata
83
87
  metadata[:timestamp] ||= clock.()
@@ -8,8 +8,8 @@ module RubyEventStore
8
8
  InvalidPageSize = Class.new(ArgumentError)
9
9
 
10
10
  class InvalidHandler < StandardError
11
- def initialize(subscriber)
12
- super("#call method not found in #{subscriber.class} subscriber. Are you sure it is a valid subscriber?")
11
+ def initialize(subscriber_klass)
12
+ super("#call method not found in #{subscriber_klass} subscriber. Are you sure it is a valid subscriber?")
13
13
  end
14
14
  end
15
15
  end
@@ -27,12 +27,16 @@ module RubyEventStore
27
27
  end
28
28
  end
29
29
 
30
+ def proxy_for(klass)
31
+ dispatcher.proxy_for(klass)
32
+ end
33
+
30
34
  private
31
35
  attr_reader :subscribers, :dispatcher
32
36
 
33
37
  def verify_subscriber(subscriber)
34
38
  raise SubscriberNotExist if subscriber.nil?
35
- raise InvalidHandler.new(subscriber) unless subscriber.respond_to?(:call)
39
+ raise InvalidHandler.new(subscriber.class) unless subscriber.respond_to?(:call)
36
40
  end
37
41
 
38
42
  def subscribe(subscriber, event_types)
@@ -4,6 +4,11 @@ module RubyEventStore
4
4
  def call(subscriber, event)
5
5
  subscriber.call(event)
6
6
  end
7
+
8
+ def proxy_for(klass)
9
+ raise InvalidHandler.new(klass) unless klass.method_defined?(:call)
10
+ ->(e) { klass.new.call(e) }
11
+ end
7
12
  end
8
13
  end
9
14
  end
@@ -6,4 +6,32 @@ RSpec.shared_examples :dispatcher do |dispatcher|
6
6
  expect(handler).to receive(:call).with(event)
7
7
  dispatcher.(handler, event)
8
8
  end
9
+
10
+ specify "returns callable proxy" do
11
+ event = instance_double(::RubyEventStore::Event)
12
+
13
+ handler = dispatcher.proxy_for(HandlerClass)
14
+ expect(handler).to receive(:call).with(event).and_call_original
15
+ dispatcher.(handler, event)
16
+ expect(HandlerClass.received).to eq(event)
17
+ end
18
+
19
+ specify "fails to build proxy when no call method defined on class" do
20
+ message = "#call method not found " +
21
+ "in String subscriber." +
22
+ " Are you sure it is a valid subscriber?"
23
+
24
+ expect { dispatcher.proxy_for(String) }.to raise_error(::RubyEventStore::InvalidHandler, message)
25
+ end
26
+
27
+ private
28
+ class HandlerClass
29
+ @@received = nil
30
+ def self.received
31
+ @@received
32
+ end
33
+ def call(event)
34
+ @@received = event
35
+ end
36
+ end
9
37
  end
@@ -120,4 +120,28 @@ RSpec.shared_examples :event_broker do |broker_class|
120
120
  broker_with_custom_dispatcher.notify_subscribers(event1)
121
121
  expect(dispatcher.dispatched).to eq([{subscriber: handler, event: event1}])
122
122
  end
123
+
124
+ it "returns callable proxy" do
125
+ proxy = broker.proxy_for(TestHandler)
126
+ expect(proxy.respond_to?(:call)).to be_truthy
127
+ end
128
+
129
+ specify "fails to build proxy when no call method defined on class" do
130
+ message = "#call method not found " +
131
+ "in InvalidTestHandler subscriber." +
132
+ " Are you sure it is a valid subscriber?"
133
+
134
+ expect { broker.proxy_for(InvalidTestHandler) }.to raise_error(::RubyEventStore::InvalidHandler, message)
135
+ end
136
+
137
+ private
138
+ class HandlerClass
139
+ @@received = nil
140
+ def self.received
141
+ @@received
142
+ end
143
+ def call(event)
144
+ @@received = event
145
+ end
146
+ end
123
147
  end
@@ -1,3 +1,3 @@
1
1
  module RubyEventStore
2
- VERSION = "0.17.0"
2
+ VERSION = "0.18.0"
3
3
  end
@@ -19,9 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.8'
22
+ spec.add_development_dependency 'bundler', '~> 1.15'
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
- spec.add_development_dependency 'rspec', '~> 3.4'
25
- spec.add_development_dependency 'pry', '~> 0'
26
- spec.add_development_dependency 'mutant-rspec', '~> 0.8.11'
24
+ spec.add_development_dependency 'rspec', '~> 3.6'
25
+ spec.add_development_dependency 'mutant-rspec', '~> 0.8.14'
27
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '1.15'
20
20
  type: :development
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: '1.8'
26
+ version: '1.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,42 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.4'
47
+ version: '3.6'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.4'
55
- - !ruby/object:Gem::Dependency
56
- name: pry
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: '3.6'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: mutant-rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 0.8.11
61
+ version: 0.8.14
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 0.8.11
68
+ version: 0.8.14
83
69
  description: Implementation of Event Store in Ruby
84
70
  email:
85
71
  - dev@arkency.com
@@ -91,7 +77,6 @@ files:
91
77
  - Gemfile
92
78
  - Makefile
93
79
  - README.md
94
- - Rakefile
95
80
  - lib/ruby_event_store.rb
96
81
  - lib/ruby_event_store/client.rb
97
82
  - lib/ruby_event_store/constants.rb
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-