Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Camelize Fields

This example alters the source of each field to use camel case, leaving the serialized name as-is.

class CamelizedSourceExtension < Blueprinter::Extension
  def around_blueprint_init(ctx)
    ctx.fields.each do |field|
      field.source = field.source.to_s.camelize(:lower).to_sym
    end
    yield ctx
  end
end

It’s the equivalent of doing this for every field:

field :foo_bar, source: :fooBar