Extending find() in a horrible way

I’m trying to scope all ActiveRecord::Base.find() calls with a
particular condition… ( I want to use some clever language here about
domains… but I’ll mess it up )

Take a look at the monster I created below. Is there a proper way to do
this without feeling queasy?

This ignores all the dynamic things as well like find_all and
find_by_name, which is sad.

( That LinkerConfiguration.current_site.id can be ignored… just an
integer )

cheers
-h

class LinkCategory < ActiveRecord::Base

def self.find(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
sql = “site_id=’#{LinkerConfiguration.current_site.id}’”
if options[:conditions] && !options[:conditions].empty?
options[:conditions] += " AND #{sql}"
else
options[:conditions] = “#{sql}”
end
args << options
super(*args)
end

end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs