varvet / serial

Plain old Ruby for generating primitive data structures from object graphs.
107 stars 2 forks source link

Allow passing the serializer to `serialize` helper method. #5

Closed Burgestrand closed 9 years ago

Burgestrand commented 9 years ago

It's a small thing, but it makes for more consistent code in the controllers if the serializer needs to be changed.

Burgestrand commented 9 years ago

Closed with 6c9d8e799eef3e9da2adf34511fcafeceb7fe2e2.

Burgestrand commented 9 years ago

A cool side-effect of this is that you can ALSO pass an on-the-fly serializer, similar to this:

render json: serialize(Person.first!) { |h, person|
  h.attribute(:name, person.name)
}

I'm not sure what I think of this as a public API, so it remains an undocumented feature.