Skip to content

Commit

Permalink
Add more documentation for 'set' method and updated error message, ad…
Browse files Browse the repository at this point in the history
…d client.set case using force option in order to clarify how to use this option since they are 2 positional hash arguments
  • Loading branch information
joecabezas committed Oct 4, 2018
1 parent 5828241 commit 022b89d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.bundle
Gemfile.lock
coverage/
.byebug_history
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/stasche/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions spec/stasche/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 022b89d

Please sign in to comment.