diff --git a/.gitignore b/.gitignore index c21ed17..dc3c835 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .bundle Gemfile.lock coverage/ +.byebug_history diff --git a/README.md b/README.md index 87c3bde..aa7f098 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,16 @@ Stasche.set(user_emails: User.where(id: ids).pluck(:email)) user_emails = Stasche.get(:user_emails) ``` +### Setting options +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 +```rb +# Session A +Stasche.set({foo: 'bar'}, force: true) + +# Session B +foo_value = Stasche.get(:foo) +``` + ### Pushing/Peeking/Popping values ```rb diff --git a/lib/stasche/store.rb b/lib/stasche/store.rb index 8d09a6b..156e5a9 100644 --- a/lib/stasche/store.rb +++ b/lib/stasche/store.rb @@ -4,7 +4,8 @@ class KeyAlreadyExistsError < StandardError def initialize(key) super( - "Key #{key} already set in stasche. Use `force: true` to override." + "Key #{key} already set in stasche. Use `force: true` to override.\n"\ + "Example: Stasche.set({foo: 'bar'}, force: true)" ) end diff --git a/spec/stasche/client_spec.rb b/spec/stasche/client_spec.rb index 58f8674..112e993 100644 --- a/spec/stasche/client_spec.rb +++ b/spec/stasche/client_spec.rb @@ -74,6 +74,10 @@ error_class = Stasche::Store::KeyAlreadyExistsError expect { client.set(foo: 'bar') }.to raise_error(error_class) end + + it 'does not throws an exception if forced' do + expect { client.set({ foo: 'bar' }, force: true) }.to_not raise_error + end end end