Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
BrowsingHistory is recording browsing history simply. it backed by Redis.
The gem has been build and tested Rails 4.2 and Ruby 2.2.3
At first, you include 2 moudles.
class User < ActiveRecord::Base
include BrowsingHistory::Browser
end
class Article < ActiveRecord::Base
include BrowsingHistory::Historizable
end
Then, you can access browsing_histories
method on a user instance to add a article to the user's browsing history.
# create a article
article = Article.new(title: 'welcome to browsing_history')
# add the article to user's browsing history
user.browsing_histories << article
# access user's browsing histories of Article class
user.browsing_histories.recent(Article)
# => [#<Article id: 1, title: "welcome to browsing_history", created_at: "2016-04-29 10:13:15", updated_at: "2016-04-29 10:13:15">]
For example,
if you want add a articls to browsing histoy when a user watch the article page,
you should add the method on article_controller#show.
# app/controllers/articles_controller
# GET /articles/:id
def show
@user.browsing_histories << @article
end
There are 4 elements working on browsing_history.
BrowsingHistory::Browser(Module)
It provide access methods to browsing_history for a browser class included it.
example: User, Crawler
BrowsingHistory::Historizable(Module)
The class included it can be recorded on browsing_history
example: Article, Review
BrowsingHistory::History(class)
It's class based on ActiveModel. It record historizable instance on browser's browsing_history
and exec some operations for them like add, where, count, clear.
BrowsingHistory::Storage(Module)
It provide abstruct interface of some kind of storages like redis, activerecord, mongoid.
It is included BrowsingHistory::History and allow it to access above storages by same methods.
There is 1 storage interface
add a follow sentence to Gemfile
# Gemfile
gem 'browsing_history'
if you want choose storage to save history or modify namespace which is key-prefix on redis, add configuration to environments or your own config file. but now, you can use :redis only as storage.
# config/environments/{your environment} or create config/initializers/browsing_history.rb
# It's default configuration
BrowsingHistory.configure do |config|
config.storage_types = %i(redis active_record)
config.storage_type = :redis
config.namespace = 'browsing_history'
end
you should include only 2 moudles.
# example models
class User < ActiveRecord::Base
include BrowsingHistory::Browser
end
class Article < ActiveRecord::Base
include BrowsingHistory::Historizable
end
you can access to browsing_history by browsing_histories method. this method is provided BrowsingHistory::Browser and return BrowsingHistory::Browser::Assosiation
BrowsingHistory::Browser::Assosiation is provided following 4 methods.
and you can give following 2 argumetns for all of the methods.
Article, article, Review, review,w
# when browser is user, historizable is Articles
user = User.first
articles = user.browsing_histories.recent(Article)
# you can give instance instead of class, both return same result.
user = User.first
article = Article.first
articles = user.browsing_histories.recent(article)
# when you want mautipul historizable such as article and review
user = User.first
articles = user.browsing_histories.recent(article)
reviews = user.browsing_histories.recent(Review)
limit, between, at, all....
# when you want to get recent 20(default) articles on browsing_history
articles = user.browsing_histories.recent(Article)
# when you want to get recent 100 articles on browsing_history
articles_100 = user.browsing_histories.recent(Article, limit: 100)
# recent
# get user's browsing histories in order form the new one
articles = user.browsing_histories.recent(Article)
articles_100 = user.browsing_histories.recent(Article, limit: 100)
# previous
# getting articles that user browsed between today to 1 day ago and in order form the new one
articles = user.browsing_histories.previous(Article, Time.zone.now..1.day.ago)
# add
# add the article to user's browsing history
user.browsing_histories << article
# count
# count user's browsing history
number_of_histories = user.browsing_histories.count(Article)
you can access browsing_history using also BrowsingHistory::History not only BrowsingHistory::Browser::Assosiation
BrowsingHistory::History is provided following 4 methods.
it's based ActiveModel and its method format is similar ActiveRecord.
user = User.create(name: 'browser')
article = Article.create(title: 'welcome to browsing_history')
# add the article to user's browsing_history
BrowsingHistories::History.create(browser: user, historizable: article)
it is able to conbine some options to access browsing_history so more flexibly than BrowsingHistory::Browser::Assosiation.
BrowsingHistories::History.where(
user: user,
historizable: review,
between: 1.day.ago..2.days.ago,
limit: 50
)
user = User.first
# where
# get user's browsing histories in order form the new one ≒ user.browsing_history.recent
articls = BrowsingHistories::History.where(user: user, historizable: Article) # default all
articls_100 = BrowsingHistories::History.where(user: user, historizable: Article, limit: 100)
# get the article 5th from the newest
article = Article.find(100)
articls_5th = BrowsingHistories::History.where(user: user, historizable: Article, at: 5)
# getting articles that user browsed between 1 day ago to 2 days ago and in order form the new one ≒ user.browsing_history.previous
articles = BrowsingHistories::History.where(user: user, historizable: review, between: 1.day.ago..2.days.ago)
# conbining some options
# getting articles that user browsed between 1 day ago to 2 days ago and it's limit 50 in order from the new one
BrowsingHistories::History.where(
user: user,
historizable: review,
between: 1.day.ago..2.days.ago,
limit: 50
)
# count
# count user's browsing history ≒ user.browsing_history.count
articls = BrowsingHistories::History.count(user: user, historizable: Article)
number_of_histories = BrowsingHistories::History.count(user: user, historizable: Article)
# clear
# clear the article from user's browsing history
article = Article.first
BrowsingHistory::History.clear(browseer: user, historizable: article)
# clear all user's browsing history
BrowsingHistory::History.clear(browseer: user, historizable: Article)
# or
article = Article.first
BrowsingHistory::History.clear(browseer: user, historizable: article, all: true)
FAQs
Unknown package
We found that browsing_history demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.