Unavailability
Unavailability simply adds a capability to manage availabilities. I extracted this gem from the work I am doing for ehochef.com where I have to allow a user to make their day either available or unavailable via a calendar (I use simple_calendar for UI).
Since we want to keep a user's availability available by default, managing i.e. adding/removing "unavailability" rather than "availability" makes sense to me; hence, the name of the gem and the logic followed in the code.
Installation
Add this line to your application's Gemfile:
gem "unavailability"
And then execute:
bundle install
Generate a migration file to create the unavailable_dates
table:
rails generate unavailable_date
Run the migration:
rails db:migrate
Edit a Model as the following:
# Since it is a Polymorphic association, it can be added to any number of Models
class User < ApplicationRecord
include Unavailability
end
Usage
Check if the model is available for a Date:
user.available_for_date?(Date.today)
Return all available Users:
User.available_for_date(Date.today)
Make a Date range unavailable:
user.make_available(from: Date.parse('2050-01-10'), to: Date.parse('2050-01-15'))
Make a Date range available:
user.make_unavailable(from: Date.parse('2050-01-08'), to: Date.parse('2050-01-08'))
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/unavailability. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant 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 Unavailability project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.