WhereChain extension gem
Stop writing Post.where('comments > ?', 10), write Post.where.gt(comments: 10) instead! GitHub repository
Rails 4 introduced WhereChain which is the class behind the ability to do Post.where.not(name: 'Foo'), however all the tries to introduce other methods to the chain were met with a strong resistance from DHH. Make a plugin, he says. Okay, fine.
This gem extends WhereChain with additional methods: .like, .unlike, .gt, .gte, .lt and .lte so that you can write things like this:
Post.where.lte(comments: 5)
Post.where.gt({ comments: 5, shares: 10 })
Post.where.not.gt(comments: 5).where.like(name: '%foo%')
The gem is tested on the latest Ruby and all current Rails versions - 4.2, 5.0, 5.1 and 5.2 RC 1
Post a comment