eventsimple 1.2.3 → 1.3.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
  SHA256:
3
- metadata.gz: c19b9d4481185e75ebfbb32cde09d5e1cf27b4ce79dac12eaa9693ad0f3888df
4
- data.tar.gz: 8907efcfdc5e08f43fa0e2f0682b3937d8866e16eaf22bf5ec34589e1d3ca8cf
3
+ metadata.gz: 638006c0e2d430bc3ef8e945b770495fecdfdf4eb96c2d7555c6f2b01d916884
4
+ data.tar.gz: b116ebfbc7fad79107f23236d249fcb1ece6a599cdd95b6489c9ca8c8dc4cf22
5
5
  SHA512:
6
- metadata.gz: f2a911cfa42750ec24803938cdee68982c7456f845b78958e6a4970f37701749e647419baafb8c80a1bafd0d061abe12f409dee6456a50a1738fbd0436c09a1f
7
- data.tar.gz: dd1f22f67d7d9d9ad88849c7e55db009e2a49b15f0a20a66387768ff03ef34e1ca100a23db829b3b09c99f978a3c7386636a2f0bd6e737743c602856cda1afa0
6
+ metadata.gz: 5cf51f1c191bd05e022bd105f056082c1b70b76b51435d74a8e241c9b2b8519a6ae874f0dd206c76101742466120415cade893695304fe5e086d7048a33f07d3
7
+ data.tar.gz: 6a37c35600d9cec4e4507a3fffecf42789e9a1108ffb5b6fcbaa1dfa6ea08554f7004a8abe5db0ae4786c2cb563e21be24de3f0e78ce14c2d2f686e63a4c006d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 1.3.0 - 2024-01-14
10
+ ### Changed
11
+ - Prevent manual write access to the entity table by default. This is to prevent
12
+ accidental writes to the entity table. Use entity.enable_writes! to enable writes.
13
+
9
14
  ## 1.2.3 - 2024-01-11
10
15
  ### Changed
11
16
  - Fix rendering of deleted events
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eventsimple (1.2.3)
4
+ eventsimple (1.3.0)
5
5
  dry-struct (~> 1.6)
6
6
  dry-types (~> 1.7)
7
7
  pg (~> 1.4)
@@ -125,6 +125,11 @@ GEM
125
125
  dry-logic (~> 1.4)
126
126
  zeitwerk (~> 2.6)
127
127
  erubi (1.12.0)
128
+ factory_bot (6.4.5)
129
+ activesupport (>= 5.0.0)
130
+ factory_bot_rails (6.4.3)
131
+ factory_bot (~> 6.4)
132
+ railties (>= 5.0.0)
128
133
  ffi (1.16.3)
129
134
  formatador (1.1.0)
130
135
  fuubar (2.5.1)
@@ -358,6 +363,7 @@ PLATFORMS
358
363
  DEPENDENCIES
359
364
  bundle-audit
360
365
  eventsimple!
366
+ factory_bot_rails
361
367
  fuubar
362
368
  git
363
369
  guard-rspec
data/README.md CHANGED
@@ -342,6 +342,24 @@ Create a rake task to run the consumer
342
342
  ## Helper methods
343
343
  Some convenience methods are provided to help with common use cases.
344
344
 
345
+ **`#enable_writes!`**
346
+ Write access on entities is disabled by default outside of writes via events. Use this method to enable writes on an entity.
347
+
348
+ ```ruby
349
+ user = User.find_by(canonical_id: 'user-123')
350
+ user.enable_writes! do
351
+ user.reproject
352
+ user.save!
353
+ end
354
+ ```
355
+
356
+ If you are using FactoryBot, you can add the following in your rails_helper.rb to enable writes on the entity:
357
+ ```ruby
358
+ FactoryBot.define do
359
+ after(:build) { |model| model.enable_writes! if model.class.ancestors.include?(Eventsimple::Entity::InstanceMethods) }
360
+ end
361
+ ``
362
+
345
363
  **`#reproject(at: nil)`**
346
364
 
347
365
  Reproject an entity from events (rebuilds in memory but does not persist the entity).
data/eventsimple.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency 'retriable', '~> 3.1'
31
31
 
32
32
  spec.add_development_dependency 'bundle-audit'
33
+ spec.add_development_dependency 'factory_bot_rails'
33
34
  spec.add_development_dependency 'fuubar'
34
35
  spec.add_development_dependency 'git'
35
36
  spec.add_development_dependency 'guard-rspec'
@@ -11,6 +11,8 @@ module Eventsimple
11
11
  autosave: false,
12
12
  validate: false
13
13
 
14
+ after_initialize :readonly!
15
+
14
16
  class_attribute :ignored_for_projection, default: []
15
17
 
16
18
  class_attribute :_filter_attributes
@@ -32,6 +34,15 @@ module Eventsimple
32
34
  attributes == reprojected.attributes
33
35
  end
34
36
 
37
+ def enable_writes!(&block)
38
+ @readonly = false
39
+
40
+ if block
41
+ yield
42
+ @readonly = true
43
+ end
44
+ end
45
+
35
46
  def reproject(at: nil)
36
47
  event_history = at ? events.where('created_at <= ?', at).load : events.load
37
48
  ignore_props = (DEFAULT_IGNORE_PROPS + ignored_for_projection).map(&:to_s)
@@ -90,7 +90,9 @@ module Eventsimple
90
90
  apply(aggregate)
91
91
 
92
92
  # Persist!
93
+ aggregate.enable_writes!
93
94
  aggregate.save!
95
+ aggregate.readonly!
94
96
 
95
97
  self.aggregate = aggregate
96
98
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eventsimple
4
- VERSION = '1.2.3'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventsimple
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zulfiqar Ali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-15 00:00:00.000000000 Z
11
+ date: 2024-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_bot_rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: fuubar
99
113
  requirement: !ruby/object:Gem::Requirement