module TemporalScopes::HasTemporalScopes
Public Instance Methods
has_temporal_scopes()
click to toggle source
Adds scopes and methods for handing temporal filtering.
## Make an `ActiveRecord` have temporal scopes
class Article < ActiveRecord::Base has_temporal_scopes end
## Archive an object
current_article = Article.create(title: 'My new article', body: 'Lorem ipsum') past_article = Article.create(title: 'My new article', body: 'Lorem ipsum') past_article.archive # or provide a datetime: past_article.archive at: 1.hour.ago
## Use temporal scopes for filtering
Article.now # => [current_article] Article.past # => [past_article] Article.with_past # => [current_article, past_article]
Note that the **default scope** is set to `now`.
Article.all # => [current_article] Article.now # => [current_article] Article.with_past # => [current_article, past_article] Article.without_temporal_condition # => [current_article, past_article]
# File lib/temporal_scopes/has_temporal_scopes.rb, line 38 def has_temporal_scopes default_scope { now } extend ClassMethods include InstanceMethods end