def find_constant(name, entry=nil)
constants = Constant.find_all_by_name(name, :include => "entries")
constants = Constant.find_all_by_name("#{name}::ClassMethods", :include => "entries") if constants.empty?
constants = Constant.all(:conditions => ["name LIKE ?", name + "%"], :include => "entries") if constants.empty?
match="%#{name.split("").join("%")}%"
constants = Constant.find_by_sql("select * from constants where name LIKE '#{match}'") if constants.empty?
regex=build_regex_from_constant(name)
constants = constants.select { |x| x.name =~ regex }
if entry
constants = constants.select { |constant| !constant.entries.find_by_name(entry).nil? }
end
constants
end