Re-using scopes from the indexed model

4 views
Skip to first unread message

Walter Lee Davis

unread,
Mar 16, 2019, 3:34:34 PM3/16/19
to thinkin...@googlegroups.com
Would it be possible to allow the scope method in real time indexing to accept the name of a scope on the indexed model? I'd like to be able to use

scope :published

rather than

scope { Speech.published }

I got an error indicating that scope expects a block (1 variable rather than 0 passed) so it occurs to me that it may be possible to wrap the current behavior in if block_given? and then drop back to

the_inferred_model.call scope_argument

or [whatever actually works with models and scopes and isn't `send`]

Any thoughts about this?

Thanks,

Walter

Pat Allan

unread,
Mar 17, 2019, 12:56:21 AM3/17/19
to thinkin...@googlegroups.com
Hi Walter,

This isn’t currently possible, though certainly it wouldn’t be hard to add that capability in, as you’ve noted. Right now I’m on the fence about whether I’d accept such a patch though - I like the idea of having one clear interface for such things (though I know I’ve not always followed that approach in the past!), and the only benefit I can think of at the moment is saving a few characters.

Are there other reasons around why this feature would be useful?

Cheers,


Pat
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to thinking-sphi...@googlegroups.com.
> To post to this group, send email to thinkin...@googlegroups.com.
> Visit this group at https://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.

Walter Lee Davis

unread,
Mar 17, 2019, 10:40:27 AM3/17/19
to thinkin...@googlegroups.com
Not really. I guess it would just fall under POLS to allow it to work. The documentation and method you have now is clear, and since there's no way I can think of to allow for chained scopes with this new syntax, all it would really be is a sugar for the lowest-hanging option. I could take a whack at a PR for this if you think it makes sense, but I'm not entirely sold on its necessity, either.

Walter

Pat Allan

unread,
Mar 17, 2019, 9:32:13 PM3/17/19
to thinkin...@googlegroups.com
Given I’m feeling ambivalent at best about such a change, I don’t think a PR is worth the time. Appreciate the discussion nonetheless!
Reply all
Reply to author
Forward
0 new messages