Skip to content

Commit 5afedd4

Browse files
authored
Merge pull request #25 from checkr/joe/force_spec
added client.set case using force option in order to clarify how to u…
2 parents 5828241 + 022b89d commit 5afedd4

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.bundle
33
Gemfile.lock
44
coverage/
5+
.byebug_history

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ Stasche.set(user_emails: User.where(id: ids).pluck(:email))
7777
user_emails = Stasche.get(:user_emails)
7878
```
7979

80+
### Setting options
81+
The set method allows you to add an `options` hash as a second parameter, for example to set a given key even if already exists
82+
```rb
83+
# Session A
84+
Stasche.set({foo: 'bar'}, force: true)
85+
86+
# Session B
87+
foo_value = Stasche.get(:foo)
88+
```
89+
8090
### Pushing/Peeking/Popping values
8191

8292
```rb

lib/stasche/store.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class KeyAlreadyExistsError < StandardError
44

55
def initialize(key)
66
super(
7-
"Key #{key} already set in stasche. Use `force: true` to override."
7+
"Key #{key} already set in stasche. Use `force: true` to override.\n"\
8+
"Example: Stasche.set({foo: 'bar'}, force: true)"
89
)
910
end
1011

spec/stasche/client_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
error_class = Stasche::Store::KeyAlreadyExistsError
7575
expect { client.set(foo: 'bar') }.to raise_error(error_class)
7676
end
77+
78+
it 'does not throws an exception if forced' do
79+
expect { client.set({ foo: 'bar' }, force: true) }.to_not raise_error
80+
end
7781
end
7882
end
7983

0 commit comments

Comments
 (0)