Tag Archive: metaprograming

Mar 17

Rspec 2.x and Fixtures

Hello, It’s been a while when I last updated this blog. It seems that Rspec 2 can not use fixtures from Activerecord 2.3.x ! Impossible ? Not really, and thanks to ruby it was possible for me. Let’s describe the background : First of all, I had a gem built on jeweler that uses ActiveSupport::TestCase …

Continue reading »

Nov 17

ActiveRecord like searching object in Rails form helpers

Ruby is a wonderful language. And Rails is a wonderful framework. Why ? Because of Duck typing !!! Example : You build a database application for a book store Books are classified by : Genre Author Country On a search page, you can search with a title text field, author select box, genre checkboxes. So …

Continue reading »

Oct 20

Ruby Rails : How to bypass skip validation in Devise

Since my last post with email validations, I was looking for a solution to integrate it with devise Sadly for me, devise implements the old way of validating email with regexp : # From devise gem version 1.1.3 validates_format_of :email, :with => email_regexp, :allow_blank => true Well, as I don’t want to hack activemodel’s code, …

Continue reading »

Aug 19

Enumerable grep method in Ruby

There is some methods that are not very known among ruby developpers. One of them is Enumerable#grep method. I would like to share one of the use case I have to face with, and how I implement grep. Purpose, I have a Hash representing a simple network I’d like to select all the people related …

Continue reading »

Sep 23

Inspectable accessors

Hey, it’s been a while I posted here. So what’s the purpose ? I commonly use script/console to debug my rails applications. Today I wanted to see the values of my custom attributes model without typing model.custom_attribute. So I took a look at ActiveRecord::Base#inspect method. and the default inspect method shows me database fields. Well, …

Continue reading »

Jul 24

Blocks are Proc : Les procédures Proc et les blocks en ruby.

( For non-french readers : I am not giving up writing in english … Read the next post! ) Si vous venez d’un autre langage, le terme procédure (associé au terme fonction) doit vous dire quelque chose. Vaguement …. Allez quelques connaissances (méconnaissances) tirées de ma mémoire pour poser les bases. Par exemple, en PHP …

Continue reading »