Giter Club home page Giter Club logo

fatboy's Introduction

Fatboy Logo

See views, right here, right now

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.

NOTE: This is currenlty not production-ready. It will be soon, though.

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, fatoby 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.

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

fatboy's People

Contributors

anthonysuper avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.