Skip to content

Commit

Permalink
feat: yield self in enable_writes! (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukashlavacka authored Sep 10, 2024
1 parent 68fb8e5 commit 6b891e8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 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
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
eventsimple (1.5.2)
eventsimple (1.5.3)
concurrent-ruby (>= 1.2.3)
dry-struct (~> 1.6)
dry-types (~> 1.7)
Expand Down Expand Up @@ -109,7 +109,7 @@ GEM
dry-core (1.0.1)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
dry-inflector (1.0.0)
dry-inflector (1.1.0)
dry-logic (1.5.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
Expand Down Expand Up @@ -184,7 +184,7 @@ GEM
minitest (5.22.2)
mutex_m (0.2.0)
nenv (0.3.0)
net-imap (0.4.11)
net-imap (0.4.16)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -207,7 +207,7 @@ GEM
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pg (1.5.6)
pg (1.5.8)
polyglot (0.3.5)
pry (0.14.2)
coderay (~> 1.1)
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 6b891e8

Please sign in to comment.