keenlabs/keen-gem — pull request #46 by vinniefranco (2014-07-30 18:47:34+00:00)
Title: [FEATURE] Keen::Modeler marshaling objects oh my!

## Usage

Say you have the following object with relationships of 1:1 and 1:M:

```ruby

@famous_order = OpenStruct.new(
title: 'Fancy pants',
order_number: 'STORE-1234'
items: [
OpenStruct.new(name: 'ACD', sku: '1234', ...),
]
customer: OpenStruct.new(name: 'Bill Murray', score: 10, ...)
)

```

And you want to send a the following structure Keen:

```ruby

{
name: 'Bill Murray',
order: 'STORE-1234',
items: [
{ name: 'ACD', sku: '1234' }
],
customer: {
score: 10
}
}

```

To marshal you just:

```ruby

modeler = Keen::Modeler.define @famous_order do
name -> { object.customer.name } # Accepts procs with object helper.
order_number as: :order # Aliases for attributes
items do
name # Simple nested calls to collections
sku
end
customer do
score
end
end

modeler.output #=> { name: 'Bill Murray', order: 'STORE-1234', items: [{ name: 'ACD', sku: '1234' }], customer: { score: 10 } }

```