“Birthday” gem for easy anniversaries handling

While working on one of our client projects, I was asked to create a search for users’ birthdays. Instantly, I remembered what problems I had with it in the past, like taking care of not only finding the right dates by only day and month, but also, checking for birthdays today, any upcoming birthdays, or even just looking up user’s age based on that information.

So, to never ever repeat that code again (and to keep the code DRY), I’ve decided to write a simple gem specifically for this stuff. And thus the birthday gem was born.

Requirements

The gem has been tested against Rails 3 (3.0.9) and Rails 2 (2.3.14), and depends on ActiveRecord and ActiveSupport (for inflections), making it a perfect fit for Rails. It is possible to use it outside Rails project, but you are required to use ActiveRecord as your ORM framework.

The gem works with MySQL and PostgreSQL adapters, but you can write your own adapters, if you need to. If you do so, it would be good to fork the gem and add it there for everybody to use. :)

So, how does it actually work?

Handling birthdays wasn’t that easy before. Here’s what you have to do in your model:

That’s all. This one line enables extra actions on the “birthday” field (of DATE or DATETIME types) in your database. For example from now on you can search for birthdays

All these methods are essentially scopes, so you could also do something like:

On top of that, you get convenience methods for single records, like getting the age:

You can get any field to behave like this. For example, let’s say we want marriage anniversaries:

And it’s done, from now on you have convenient scopes to search and handle anniversaries:

Final words

I’ve done this gem, because I never ever want to write this piece of code again, I’d rather spend my time on actually coding the important stuff in applications, than to fiddle around with dates and birthdays. Hope this gem will be of some use to you. If not, fork it, and patch it to your needs! :)

Backlash @ Robot Unicorn Invasion Party 2011

Backlash @ Robot Unicorn Invasion Party 2011 by Backslash on Mixcloud

Help You need somebody; Help not just anybody!

Here at Railslove, we love building web applications. But aside from our core business, we also help other startups understand how the web works and what it means to run a web business — in Hamburg, Berlin, Cologne. And since experienced Ruby on Rails developers are increasingly hard to find, we’ve started to offer apprenticeships, too.

One of our new partners is DailyDeal. We’ve done some beginners and advanced courses in Rails covering stuff like testing, building APIs, advanced JavaScript coding and general design and programming patterns in Ruby on Rails, etc.

Oliver Hepfner, Director Software Engineering of DailyDeal:

The training Railslove provided under the direction of Georg Leciejewski helped us understand advanced programming patterns in Ruby on Rails. Our developers were excited to get a hands-on introduction into Ruby on Rails.

 

Next month, we will launch a few more courses with DailyDeal and with other companies, like Adcloud GmbH in Germany. If you are interested in learning more, please contact Ralph and Georg: ralph AT railslove.com & gl AT salesking.eu & team AT railslove.com

Travis – a distributed build system

Let us introduce us to Travis. What is Travis? As you can read on Github:

Travis is an attempt to create an open-source, distributed build system for the Ruby community that:

  1. allows open-source projects to register their repository and have their test-suites run on demand
  2. allows users to contribute build capacities by connecting a VM that runs a build agent somewhere on their underused servers

Travis Logo You can and should use travis for your open source projects as an continuos integration system. Travis is an incredible project and helps increase the quality of  lots of Open Source projects. So please head over to travis and setup tests for your ruby, node.js, erlang, … projects. – you can also setup your own instance installing Travis and use it for your private projects.

For more information check out the github page and the getting started section.

We’re really happy to be able to support Travis by sponsoring one of the worker boxes.

btw. Sven, Josh, thanks for mentioning us on your talks at Ruby Lugdunum and Frozen Rails 2011 this year. ;)

Btw.: have you heard about the Awesome Bot Factory? With the Awesome Bot Factory you’re able to create bots for your campfire channel. There is a bot to integrate travis to your campfire chat: simply ask the bot for a given status, like:

Jan travis:status Nerds/NerdPursuit
Choco Bits Bot Nerds/NerdPursuit is stable

Or get notified about your project’s new travis builds.

- Thank you, Travis-CI!

Resources:

The DevHouseFriday Chillout and the stolen Adcloud chair

First of all – a big, big thank you to @adcloud for hosting last DevHouseFriday. The location is perfect for such events – nice conference room, a terrace, free beer and some food. Thanks again!

The last DevHouseFriday had cool talks too: @tisba talked about loadtesting in the cloud @killerg was talking about his PDF-Dragon idea, we had a interesting talk about Scala and Closures for Java (by TJ) so, thanks again.

Unfortunately someone has stolen an @adcloud chair from the office. Turns out it was one of the Railslove guys. At the event only handful of Railslovers were present: Georg, Jan, Lars, Michael and Dirk…. Apparently, it was Jan. He got his punishment for this. Now this Chair is his burden to bear, and he has to take it on every other DevHouseFriday Chillout meetup.

the devhousefriday chair

So, see you next time, the next DevHouse Friday Chillout is on the October, 21th. Venue will be announced soon. Jan the Chairman will also be there to throw rocks at.

← Previous PageNext Page →