All,
In the course of working on a change for the meta-search gem I''ve run
into an issue with the way that scopes are implemented in
ActiveRecord. In order to include a scope in a search we pass the name
of the scope to a search method like so: {:name_of_my_scope => 1}.
Meta-search automatically passes the "1" as an argument to the scope.
This causes an ArgumentError with lambda scopes that don''t take an
argument.
My intention was to check the arity of the scope before calling and
dropping the "1" in the event the scope didn''t take an
argument. My
issue is that the implementation of scope wraps scope_options up in a
lambda that passes *args to the block (active_record/named_scope.rb:
106). This results in the call to arity always returning -1 regardless
of the actual number of arguments required by the scope definition.
Is there a different way to implement scopes that would allow exposing
the arity from the scope definition?
Ex.
class Post < ActiveRecord::Base
scope :today, lambda {where(:created_at => (Time.new.beginning_of_day)…
(Time.new.end_of_day)) }
end
irb> Post.today.arity # => -1
Thanks,
Matthew
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.