Skip to content

patorash/acts_as_footprintable

Repository files navigation

ActsAsFootprintable

Test

Acts As Footprintable is a Ruby Gem specifically written for Rails/ActiveRecord models. The main goals of this gem are:

  • Allow any model to leave footprints
  • Get access ranking for footprintable model
  • Get access histories by footprinter model

Installation

Rails 5.x, 6.x and 7.0

Add this line to your application's Gemfile:

gem 'acts_as_footprintable', '~> 0.6.0'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install acts_as_footprintable

Database Migrations

Acts As Footprintable uses a footprints table to store all footprints information. To generate and run the migration just use.

$ rails generate acts_as_footprintable:migration
$ rake db:migrate

Usage

Footprintable models

class Post < ActiveRecord::Base
  acts_as_footprintable
end

@post = Post.create(name: 'my post!')

@post.leave_footprints @user
@post.footprints.size # => 1

Footprintable model access ranking

# Total access ranking
total_ranking = Post.access_ranking

# Span access ranking
monthly_ranking = Post.access_ranking(1.month.ago.beginning_of_month..1.month.ago.end_of_month)

# Limit access ranking
monthly_top10_ranking = Post.access_ranking(1.month.ago.beginning_of_month..1.month.ago.end_of_month, 10)
# => {footprintable_id => count, ...}

Footprinter models

class User < ActiveRecord::Base
  acts_as_footprinter
end

@user.leave_footprints @post
@post.footprints.size # => 1

Footprinter model access histories

# Total access histories
total_access_histories = @user.access_histories
# Limited total access histories
total_access_histories = @user.access_histories(10)

# Post access histories
post_access_histories = @user.access_histories_for Post
# Limited Post access histories
post_access_histories = @user.access_histories_for(Post, 10)

Testing

$ bundle exec rake

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Rails gem to allowing records to leave footprints

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages