karmi/tire — Issue #184: Better DSL
Author: haihappen
Created: 2011-12-23 21:40:56+00:00
State: open

At the moment Tire isn't very flexibly when custom attributes are needed for searching. I'm often ending up mixing `mapping` and `to_indexed_json`. One model doesn't use custom attributes so it defines its searchable attributes via `mapping` – which is imho the better and far more beautiful way –, another models need one stupid custom attribute and I'm forced to use `to_indexed_json`. It's not really a problem, but it just doesn't feel right.

How about implementing something like this:

```ruby
class Article
belongs_to :author

mapping do
indexes :author, as: ->{ author.name }
indexes :author_email, as: 'author.email'
end
end
```

My idea is to implement another option for the `indexes` method, maybe `:as` which accepts a lambda/proc or a string which will be evaluated at indexing time. Any thoughts?