karmi/retire — pull request #904 by rafael (2013-11-08 18:24:48+00:00)
Title: Instance eval with delegation proof of concept.

Hi,

I've been using tire and I've been facing the following issue. Sometimes, I would like to use some helper methods within the search blocks, but I always get an undefined method. In the current state, the only work around that I found for that so far is to write the search methods like this:

```ruby

def execute
Model.tire.search(page: page, load: true) do |s|
s.query do |q|
q.boolean do |b|
b.must { |condition| condition.string "..." } if tags
...
end
...
end
s.sort { by :id, "desc" }
end
end

def tags
...
end
```

I notice that this has to do with the use of instance eval inside the DSL. I found this interesting article where they explained a workaround for that:

http://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation

I started a proof of concept to see if it works with tire. It seems to be working.

Is there a reason why you guys didn't allow this? I could implement this in all the other places, but I wanted to have your feedback, I don't know if I'm missing something here and there is a reason to not do this.

Cheers!