Skip to content

Commit

Permalink
feat: yield self to enable_writes! &block
Browse files Browse the repository at this point in the history
  • Loading branch information
lukashlavacka committed Sep 9, 2024
1 parent 68fb8e5 commit 4ee6cc3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 1.5.3 - 2024-09-09
### Changed
- Pass self to `enable_writes!` block

## 1.5.2 - 2024-05-22
### Changed
- Add created_at index in events migration generation
Expand Down
2 changes: 1 addition & 1 deletion lib/eventsimple/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def enable_writes!(&block)
@readonly = false

if block
yield
yield self
@readonly = true if was_readonly
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/eventsimple/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Eventsimple
VERSION = '1.5.2'
VERSION = '1.5.3'
end
6 changes: 6 additions & 0 deletions spec/lib/eventsimple/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ module Eventsimple
end

context 'when enabled with a block' do
it 'passes self into the block' do
user.enable_writes! do |entity|
expect(entity).to eq(user)
end
end

context 'when the entity was readonly before' do
it 'restores readonly status after the block' do
user.readonly!
Expand Down

0 comments on commit 4ee6cc3

Please sign in to comment.