Created
November 12, 2010 23:07
-
-
Save iosadchiy/674864 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.find(*args) | |
ret = nil | |
if args.first.is_a? Symbol | |
if args.first == :all | |
ret = Array.new | |
if args[1].is_a? Hash | |
Company.all.each do |a| | |
tests = Array.new | |
args[1][:conditions].each do |atr, cond| | |
if a.read_attribute(atr) != cond | |
tests << false | |
else | |
tests << true | |
end | |
end | |
unless tests.include? false | |
ret << a | |
end | |
end | |
end | |
elsif args.first == :first | |
if args[1].is_a? Hash | |
Company.all.each do |a| | |
tests = Array.new | |
args[1][:conditions].each do |atr, cond| | |
if a.read_attribute(atr) != cond | |
tests << false | |
else | |
tests << true | |
end | |
end | |
unless tests.include? false | |
ret = a | |
break a | |
end | |
end | |
end | |
else | |
super | |
return | |
end | |
return ret | |
else | |
super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment