0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
month_constrain is a re-implementation of acts_as_month_constrain for Rails 4, and 5.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.0
~> 0.43
~> 1.0

Runtime

 Project Readme

MonthConstrain

month_constrain is for managing columns of Date type as month information in ActiveRecord. Converts date information such as Date.new(2016, 12, 12) and "2016-01" to Date Class.

Supports Rails 4.x and 5.x releases.

Installation

Add this line to your application's Gemfile:

gem 'month_constrain'

And then execute:

$ bundle

Or install it yourself as:

$ gem install month_constrain

Usage

In your model

class Book < ApplicationRecord
  acts_as_month_constrain :published_on

  # ...
end

Create Record

e.g.

>> Client.create(published_on: '2016-01')
# => #<Client id: 1, published_on: "2016-01-01">

>> Client.create(published_on: Date.new(2016, 1, 16))
# => #<Client id: 1, published_on: "2016-01-01">

Find Record

e.g.

>> Client.published_on('2016-01')
# => #<ActiveRecord::Relation [#<Client id: 1, published_on: "2016-01-01">]>

>> Client.published_on(Date.new(2016, 1, 16))
# => #<ActiveRecord::Relation [#<Client id: 1, published_on: "2016-01-01">]>

>> Client.published_on_in(Date.new(2016, 1, 16), nil)
# => #<ActiveRecord::Relation [#<Client id: 5, published_on: "2016-01-01">, #<Client id: 6, published_on: "2016-02-01">, #<Client id: 7, published_on: "2016-03-01">]>

>> Client.published_on_in('2016-01', '2016-02')
# => #<ActiveRecord::Relation [#<Client id: 5, published_on: "2016-01-01">, #<Client id: 6, published_on: "2016-02-01">]>

Contributing

  1. Fork it ( https://github.com/speee/month_constrain/fork )
  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 a new Pull Request

License

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