6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/mongomapper_token.rb', line 6
def token(*args)
options = args.
options[:length] ||= 4
options[:contains] ||= :alphanumeric
options[:index] = true unless options.has_key?(:index)
self.key :token, :type => String
self.ensure_index [[:token, 1]], :unique => true if options[:index]
set_callback(:create, :before) do |document|
document.create_token(options[:length], options[:contains])
end
set_callback(:save, :before) do |document|
document.create_token_if_nil(options[:length], options[:contains])
end
end
|