13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/wuid/wuid.rb', line 13
def self.find(*args)
options = args.
validate_find_options(options)
set_readonly_option!(options)
case args.first
when :first
find_initial(options)
when :last
find_last(options)
when :all
find_every(options)
else
expects_array = args.first.is_a?(Array)
return args.first if expects_array && args.first.empty?
case args.size
when 0
raise "Couldn't find #{name} without an ID"
when 1
if args[0].to_s.size != RAND_TOKEN_SIZE
raise "Wuid format error"
else
if args[0].is_a?(Array)
if args[0].all?{|i| i.is_a?(Integer)} || args[0].all?{|i| i=~ /^\d{1,}$/}
raise "Don't support simple digest id any more"
else
origin_find(:all, :conditions => ["rand_token in (?)", args[0]])
end
else
origin_find(:first, :conditions => ["rand_token = ?", args[0]])
end
end end end end
|