squeel icon indicating copy to clipboard operation
squeel copied to clipboard

sifter :name => def name, unclear

Open ronalchn opened this issue 14 years ago • 1 comments

I found out that using:

sifter :name do |args|

end

actually defines a method of that name, which means you cannot subsequently say

def name

end

This is not stated clearly in the documentation, and may confuse users.

Having said that, I think it is perhaps a mistake that sifters are placed in the same namespace as methods in the class.

First of all, you would never really want to call a sifter directly, and second, it pollutes the ActiveRecord object.

For example, if I say

scope :active, where(:is_active => true)

sifter :active do
  return is_active
end

then we have a name clash. This is the kind of thing many people may do. That is because if we call active, we intend to use the scope to narrow the ActiveRelation objects found. On the other hand, we would never want to call the sifter :active directly, because we use it in for example where( sift(:active) | sift(:other_conditions)). Notice that the symbol always goes through sift first?


I think sifter methods should be moved into some other namespace (perhaps inside a special object with some obscure name). That would avoid name clashes, and allow people to have scopes and sifters of the same name.

ronalchn avatar Aug 24 '12 11:08 ronalchn

I plan to change the sifter implementation slightly in 1.1, which will alleviate this issue. For 1.0.x it's staying as is.

ernie avatar Aug 24 '12 11:08 ernie