The project is in a healthy, maintained state
Add scopes to enum in rails with after and before queries for enums that have chronologicality
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 5.2
 Project Readme

ChronologicalEnum

ChronologicalEnum is a Ruby gem that extends ActiveRecord enums to provide dynamic scopes for enums with values in a specified order.

For example

class MyClass < ApplicationRecord
  enum status: { created: 0, processed: 1, finished: 2 }, _chronological: true
end

# Scope examples
MyClass.after_created # returns records with status greater than created
MyClass.before_finished # returns records with status lower than finished
MyClass.after_or_processed # returns records with status greater or equal to processed
MyClass.before_or_processed # returns records with status lower or equal to finished

It also supports prefixes and suffixes.

class MyClass < ApplicationRecord
  enum status: { created: 0, processed: 1, finished: 2 }, _prefix: 'my', _suffix: 'enum',_chronological: true
end

MyClass.after_my_status_enum # returns records with status greater than created

The enum values have to be integers otherwise ChronologicalEnum would not work.

Installation

Add this line to your application's Gemfile:

gem 'chronological_enum'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install chronological_enum

Usage

Just add _chronological: true to your enum definition as shown above.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nicmey/chronological_enum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

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

Code of Conduct

Everyone interacting in the chronologicalEnum project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.