Project

fatboy

0.0
No commit activity in last 3 years
No release in over 3 years
Fatboy is a gem designed to easily keep track of views. It doesn't touch your SQL, and stays slim in redis. It also makes it easy to query based on how viewed something is.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.6, ~> 1.6
>= 0.14.0, ~> 0.14.0
>= 0
>= 3.2, ~> 3.2.0
>= 0.9.2, ~> 0.9.2
>= 0.7, ~> 0.7.3

Runtime

>= 3.2, ~> 3.2.1
 Project Readme

Fatboy Logo

See views, right here, right now

Build Status Code Climate Test Coverage

Fatboy is a gem which manages view counts on ActiveRecord objects (or things that quack like them).

It's great for seeing the most (and least) viewed models on your website. To make things even better, Fatboy will store view counts by day, month, year, and all-time.

It doesn't touch your SQL database. Fatboy stays slim in Redis.

Installation

Add this line to your application's Gemfile:

gem 'fatboy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fatboy

Usage

Fatboy is easy to set up. First, initialize it:

  # if you don't provide your own redis, fatboy will create one 
  # with Redis.new
  fatboy = Fatboy.new(redis: redis)

Then, just tell it what your users look at.

  # As long as the variable you're passing in responds to
  # .id, this will work
  fatboy.view(image)
  # You can also use the shorthand method:
  # fatboy[image]

Now, managing views is pretty useless if you can't retrieve them later. Thankfully, fatboy makes this easy as well:

  fatboy.views_for(image).today # => 1
  fatboy.views_for(image).this_year # => 1

Don't worry if that's a brand-new Fatboy instance---as long as the Redis is the same, Fatboy's view count will be the same.

Getting Top Viewed

Fatboy makes it easy to retrieve a list of the most-popular records in your database. Check it now now:

  fatboy.popular(Image).today.most # => most viewed image today

Want it from other days?

  # most popular image a month ago
  fatboy.popular(Image).day(Time.now << 1).most
  # Or with active support
  fatboy.popular(Image).day(1.months.ago).most

Don't want just the most popular? Maybe you'd like the least popular?

  fatboy.popular(Image).day(Time.now).least
  fatboy.popular(Image).month(Time.now).least

Or perhaps a range?

  fatboy.popular(Image).this_month.range(10..20)
  # or, a range for a while ago
  fatboy.popular(Image).month(3.months.ago).range(10..20)

Fatboy makes it easier. See the rdoc for details.

Pipelined

If you need to view lots of models at once, you may find Fatboy::Many to be a good option. Check it out now:

  m = fatboy.many
  m[image]
  comments.each{|c| m[c]}
  m[description]
  m.commit!

Contributing

  1. Fork it ( https://github.com/AnthonySuper/fatboy/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write functionality and tests
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request