🎉 Enhanced counter management for your Ruby on Rails app.
Add this line to your application's Gemfile:
gem 'fancy_count'And then execute:
$ bundle install
Or install it yourself as:
$ gem install fancy_count
Make sure to define which adapter you want to use to persist the counters.
# config/initializers/fancy_count.rb
require 'fancy_count'
FancyCount.configure do |config|
config.adapter = :redis
endFancy count is dead simple to drop in and get going.
Example usage in IRB
counter = FancyCount::Counter.new('my-counter')
counter.increment
counter.value # => 1
counter.decrement # => 0Example usage in an ActiveRecord Model
class Company < ApplicationRecord
include FancyCount::HasCountable
fancy_counter :employees
end
company = Company.new
company.fancy_employee_count # => 0
company.fancy_employee_counter.increment
company.fancy_employee_count # => 1Example Counter Cache
class Company < ApplicationRecord
include FancyCount::HasCountable
fancy_counter :employees
end
class Employee < ApplicationRecord
include FancyCount::CounterCacheable
belongs_to :company
fancy_counter_cache :employees, on: :company
end
company = Company.first
company.fancy_employee_count # => 0
company.employees.create(name: "bob marley")
company.fancy_employee_count # => 1
company.employees.destroy_all
company.fancy_employee_count # => 0After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
- install gem-release https://github.com/svenfuchs/gem-release
- run
gem bump --version patchif patching (otherwise switch "patch" out for "minor" or "major") - run
gem tag 1.x.xreplacing the "x" characters with appropriate values - run
git push --tags originto push the tags up to Github - Finally, run
gem releasewhich pushes the gem up to whatever repository (ex: Rubygems)
Bug reports and pull requests are welcome on GitHub at https://github.com/CompanyCam/fancy-count. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the FancyCount project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.