rails_event_store 0.1.2 → 0.1.3

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: b92227a5b22816861dab6e283090912863e3c60f
4
- data.tar.gz: 460ea96f8e15e7a79a406c1e12dcb43293c2f518
3
+ metadata.gz: 5e7e79b6ac4baf7aefef23a90ef89ca16e8704b4
4
+ data.tar.gz: a4fd3f1e1fd6ab6ce86b8bdf8c4cb52474c47546
5
5
  SHA512:
6
- metadata.gz: 0f9162341516cb547bd46adf076ceeb48c36309beb5947be4a7f89bc52a2eeba48a47e9fed59e35c31478ad05b91f5c3604754a51b03c9f2cedeefd5f155a8c5
7
- data.tar.gz: 273c27809b1c4695b4c1c99e6b3e17319c3575706fba7cb426fa46cd8208400d43d6357082bffa16085ccb5eaf15943d2b78e069ff34c79a62380591d0151628
6
+ metadata.gz: 9da2db327c6968a2614fa7a4b2ca570ef3394db5e8fdd573a9a85ac90e0d7c3fc77cabd116c27d2f2893f84488fe4d89dfec0ef3c4b3553aa301f3b38da8c0e7
7
+ data.tar.gz: 42f2f823e3a1d4e72b2c2e9c136e58732bbea338df6eb3528209141f24fa7d418c9220c8f1d0449ebd86fe2a33f2869f86afd6be3f56f55b4a5a31233741ab39
data/README.md CHANGED
@@ -131,7 +131,7 @@ client.subscribe(invoice, ['PriceChanged', 'ProductAdded'])
131
131
 
132
132
  ```ruby
133
133
  invoice = InvoiceReadModel.new
134
- client.subscribe(invoice)
134
+ client.subscribe_to_all_events(invoice)
135
135
  ```
136
136
 
137
137
  #### Resources
@@ -142,3 +142,11 @@ There're already few blogposts about Rails EventStore. Check them out:
142
142
  * [The Event Store for Rails developers](http://blog.arkency.com/2015/04/the-event-store-for-rails-developers/)
143
143
  * [Fast introduction to Event Sourcing for Ruby programmers](http://blog.arkency.com/2015/03/fast-introduction-to-event-sourcing-for-ruby-programmers/)
144
144
  * [Why I want to introduce mutation testing to the rails_event_store gem](http://blog.arkency.com/2015/04/why-i-want-to-introduce-mutation-testing-to-the-rails-event-store-gem/)
145
+
146
+ ## About
147
+
148
+ <img src="http://arkency.com/images/arkency.png" alt="Arkency" width="20%" align="left" />
149
+
150
+ Rails Event Store is funded and maintained by Arkency. Check out our other [open-source projects](https://github.com/arkency).
151
+
152
+ You can also [hire us](http://arkency.com) or [read our blog](http://blog.arkency.com).
@@ -1,4 +1,5 @@
1
1
  require 'rails_event_store/event_entity'
2
+ require 'rails_event_store/models/event'
2
3
  require 'rails_event_store/generators/migrate_generator'
3
4
  require 'rails_event_store/generators/templates/migration_template'
4
5
  require 'rails_event_store/version'
@@ -10,4 +11,3 @@ require 'rails_event_store/aggregate_root'
10
11
  require 'rails_event_store/errors'
11
12
  require 'rails_event_store/client'
12
13
  require 'rails_event_store/constants'
13
- require 'rails_event_store/utils/string_utils'
@@ -1,3 +1,5 @@
1
+ require 'active_support/inflector'
2
+
1
3
  module RailsEventStore
2
4
  module AggregateRoot
3
5
  def apply(event)
@@ -16,7 +18,7 @@ module RailsEventStore
16
18
  private
17
19
 
18
20
  def apply_event(event)
19
- public_send("apply_#{StringUtils.underscore(event.event_type)}")
21
+ send("apply_#{event.event_type.underscore.gsub('/', '_')}", event)
20
22
  end
21
23
 
22
24
  def generate_uuid
@@ -1,10 +1,10 @@
1
- require 'active_record'
1
+ require 'active_model'
2
2
 
3
3
  module RailsEventStore
4
- class EventEntity < ActiveRecord::Base
5
- self.primary_key = :id
6
- self.table_name = 'event_store_events'
7
- serialize :metadata
8
- serialize :data
4
+ class EventEntity
5
+ include ::ActiveModel::Model
6
+
7
+ attr_accessor :id, :stream, :event_type, :event_id,
8
+ :metadata, :data, :created_at
9
9
  end
10
- end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+
3
+ module RailsEventStore
4
+ module Models
5
+ class Event < ::ActiveRecord::Base
6
+ self.primary_key = :id
7
+ self.table_name = 'event_store_events'
8
+ serialize :metadata
9
+ serialize :data
10
+ end
11
+ end
12
+ end
@@ -3,54 +3,55 @@ module RailsEventStore
3
3
  class EventRepository
4
4
 
5
5
  def initialize
6
- @adapter = EventEntity
6
+ @adapter = ::RailsEventStore::Models::Event
7
7
  end
8
8
  attr_reader :adapter
9
9
 
10
10
  def find(condition)
11
- adapter.where(condition).first
11
+ build_event_entity adapter.where(condition).first
12
12
  end
13
13
 
14
14
  def create(data)
15
- begin
16
- adapter.create(data)
17
- rescue ActiveRecord::RecordNotUnique
18
- raise EventCannotBeSaved
19
- end
15
+ build_event_entity adapter.create(data)
16
+ rescue ActiveRecord::RecordNotUnique
17
+ raise EventCannotBeSaved
20
18
  end
21
19
 
22
20
  def delete(condition)
23
21
  adapter.destroy_all condition
22
+ nil
24
23
  end
25
24
 
26
25
  def get_all_events
27
- adapter.find(:all, order: 'stream').map &method(:map_record)
26
+ adapter.find(:all, order: 'stream').map &method(:build_event_entity)
28
27
  end
29
28
 
30
29
  def last_stream_event(stream_name)
31
- adapter.where(stream: stream_name).last.map &method(:map_record)
30
+ adapter.where(stream: stream_name).last.map &method(:build_event_entity)
32
31
  end
33
32
 
34
33
  def load_all_events_forward(stream_name)
35
- adapter.where(stream: stream_name).order('id ASC').map &method(:map_record)
34
+ adapter.where(stream: stream_name).order('id ASC').map &method(:build_event_entity)
36
35
  end
37
36
 
38
37
  def load_events_batch(stream_name, start_point, count)
39
- adapter.where('id >= ? AND stream = ?', start_point, stream_name).limit(count).map &method(:map_record)
38
+ adapter.where('id >= ? AND stream = ?', start_point, stream_name).limit(count).map &method(:build_event_entity)
40
39
  end
41
40
 
42
41
  private
43
42
 
44
- def map_record(record)
45
- event_data = {
46
- stream: record.stream,
47
- event_type: record.event_type,
48
- event_id: record.event_id,
49
- metadata: record.metadata,
50
- data: record.data
51
- }
52
- OpenStruct.new(event_data)
43
+ def build_event_entity(record)
44
+ ::RailsEventStore::EventEntity.new(
45
+ id: record.id,
46
+ stream: record.stream,
47
+ event_type: record.event_type,
48
+ event_id: record.event_id,
49
+ metadata: record.metadata,
50
+ data: record.data,
51
+ created_at: record.created_at
52
+ )
53
53
  end
54
+
54
55
  end
55
56
  end
56
57
  end
@@ -1,3 +1,3 @@
1
1
  module RailsEventStore
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -24,6 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rspec'
25
25
  spec.add_development_dependency 'rails', '~> 4.2.1'
26
26
  spec.add_development_dependency 'webmock', '~> 1.21.0'
27
+
27
28
  spec.add_dependency 'ruby_event_store'
29
+ spec.add_dependency 'activesupport', '>= 3.0'
30
+ spec.add_dependency 'activemodel', '>= 3.0'
28
31
 
29
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rybex
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activemodel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
111
139
  description: Implementation of Event Store in Ruby
112
140
  email:
113
141
  - tomek.rybka@gmail.com
@@ -132,9 +160,9 @@ files:
132
160
  - lib/rails_event_store/event_handlers/slack_event_handler.rb
133
161
  - lib/rails_event_store/generators/migrate_generator.rb
134
162
  - lib/rails_event_store/generators/templates/migration_template.rb
163
+ - lib/rails_event_store/models/event.rb
135
164
  - lib/rails_event_store/repositories/aggregate_repository.rb
136
165
  - lib/rails_event_store/repositories/event_repository.rb
137
- - lib/rails_event_store/utils/string_utils.rb
138
166
  - lib/rails_event_store/version.rb
139
167
  - rails_event_store.gemspec
140
168
  homepage: ''
@@ -156,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
184
  version: '0'
157
185
  requirements: []
158
186
  rubyforge_project:
159
- rubygems_version: 2.4.3
187
+ rubygems_version: 2.4.8
160
188
  signing_key:
161
189
  specification_version: 4
162
190
  summary: Implementation of Event Store in Ruby
@@ -1,14 +0,0 @@
1
- module StringUtils
2
- def self.underscore(camel_cased_word)
3
- acronym_regex = /(?=a)b/
4
- return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
5
- word = camel_cased_word.to_s.gsub(/::/, '/')
6
- word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" }
7
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
8
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
9
- word.tr!("-", "_")
10
- word.downcase!
11
- word.gsub!(/[^A-Za-z0-9_]/, '_')
12
- word
13
- end
14
- end