I'm working on a plugin that adds ThinkingSphinx to a model, and I'm
learning a lot about Ruby's metaprogramming in the process.

I've learned that although I can open my model and add to it without a
problem, this starts to break down if I try to add anything to it that
isn't defined in the Ruby libraries (ie, 'has_many', or
'define_index'). Adding has_many was easy
(Article.send :has_many, :comments), but I'm not sure how to proceed
for define_index.

Here's what I'm starting with:

class Article < ActiveRecord::Base
  define_index do
    indexes title, :sortable => true
    indexes description
    indexes post
  end
end

I imagine that would take the form of Article.send(:define_index,
&some_block) but the tricky part for me seems to be in defining
some_block. I'm not sure how to go about doing this. I tried the
following:

Article.send :define_index, lambda do
  indexes title, :sortable => true
  indexes description
  indexes post
end

but received "tried to create Proc object without a block". I tried:

Article.send :define_index, &(lambda do
  indexes title, :sortable => true
  indexes description
  indexes post
end)

but received "undefined method `define_index' for #<Class:0x6d8d380>",
which is the same thing I get if I just re-open 'Article' and add a
call to define_index in the first place. This code is at the far
reaches of the map for me, both in terms of Ruby and of TS. Any ideas
on the correct syntax for this sort of thing?
-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.


Reply via email to