It’s plugin / gem pimping time!
I started writing by_star back in November 2008 when Thomas Sinclair asked me if I could write a method that could find records for a given month. I was in my gem creating phase then so I created a gem called by_month and Thomas paid me for it (the sucker!).
Later on, I realised that by_month wasn’t good enough so I added a couple more finders to it. Then I added some more. Now you can find by all of these things:
- A given year
- A given month
- A given fortnight
- A given week
- A given weekend
- A given day
- The current weekend
- The current work week
- The Past
- The Future
- Between certain times
- As of a certain time
- Up to a certain time
- Before a specific record
- After a specific record
So if you’re ever doing anything in your application where you need to find by dates / times, why are you not using by_star? Here’s a good reason you should be using by_star:
Before by_star
Post.all(:conditions => ["created_at >= ? AND created_at <= ?", "01/01/#{Time.now.year}".to_time, "31/01/#{Time.now.year}"])
After by_star
Post.by_month(1)
This is only a taste of the shiny things in by_star! Use it!