Giter VIP home page Giter VIP logo

has_duration's Introduction

HasDuration

Do you use rails time convenience methods? Those things are great, they let you do stuff like 1.day.from_now or Time.now - 10.years. The 10.years part is an {ActiveSupport::Duration} object.

This plugin extends ActiveRecord so you can conveniently store durations like: how often to contact a given customer, or how long can your users stay in the bathtub without their fingertips wrinkling.

Installation: Add this to your Gemfile

gem 'has_duration'

Given a table defined as:

create_table :users do |t|
  t.string :contact_every, null: false
  t.string :bathtub_tolerance
end

You can have a model like this

class User < ActiveRecord::Base
  has_duration :contact_every
  # Has duration does not validate presence, you have to do that yourself.
  validates :contact_every, presence: true
  has_duration :bathtub_tolerance
end

user = User.create!(contact_every: 1.year, bathtub_tolerance: 30.minutes)
puts 'that must be a record' if customer.bathtub_tolerance > 3.hours
puts "If contacted today, next contact would be made on #{user.contact_every.from_now}"

This project uses MIT-LICENSE.

has_duration's People

Contributors

nubis avatar

Watchers

Ng Tze Yang avatar Wong Liang Zan avatar kj avatar James Cloos avatar Tomas Rojas avatar Dicky Arinal avatar Ron Hart avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.