atcruice / timely_scopes

A Rails plugin to add handy, time-based scopes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TimelyScopes

A Rails plugin to add handy, time-based scopes.

Usage

Given a model:

# db/migrate/XXXXXXXXXXXXXX_create_asdfs.rb
class CreateAsdfs < ActiveRecord::Migration[6.0]
  def change
    create_table :asdfs do |t|
      t.date :dated_on
      t.datetime :datetimed_at
    end
  end
end

Include the TimelyScopes module and declare the scopes you want using add_timely_scopes:

# app/models/asdf.rb
class Asdf < ApplicationRecord
  include TimelyScopes

  add_timely_scopes(
    :dated_after,
    :dated_before,
    :dated_from,
    :dated_until,
    :datetimed_after,
    :datetimed_before,
    :datetimed_from,
    :datetimed_until,
  )
end

Installation

Add this line to your application's Gemfile:

gem "timely_scopes"

And then execute:

$ bundle

License

The gem is available as open source under the terms of the MIT License.

About

A Rails plugin to add handy, time-based scopes.

License:MIT License


Languages

Language:Ruby 80.2%Language:HTML 15.4%Language:JavaScript 2.2%Language:CSS 2.1%