Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom Tracking Strategies #172

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jessedoyle
Copy link

Hey there! Thanks for making an awesome library!

I recently ran into a use case where it would be convenient to introduce an alternate strategy when updating the use_count column. In particular, the goal was to move the write database operation out of the request lifecycle into a background job.

Previously this customization would require a monkey patch of the Shortener::ShortenedUrl#increment_usage_count method (similar the approach taken in #170).

This PR adds a new configuration option to make it simple to specify the tracking behaviour. The option default doesn't break existing functionality, and operates as follows:

Shortener.increment_usage_count = ->(url) do
  MyBackgroundJob.perform_later(url)
end

Happy to hear any feedback or suggestions, but it seems like this could be a useful addition to the library. Thanks!

Previously customizing the tracking strategy required monkey patching
core methods such as `Shortener::ShortenedUrl#increment_usage_count`.

Some implementations may want to easily configure the URL tracking
strategy, or disable it entirely.

This commit adds a new configuration option to specify the behaviour,
with a default value that does not break existing functionality. The
strategy can be configured as follows:

```ruby
Shortener.increment_usage_count = ->(url) do
  MyBackgroundJob.perform_later(url)
end
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant