2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/couchdb_oauth2/model/oauth2_token.rb', line 2
def self.included(klass)
klass.class_eval do
cattr_accessor :default_lifetime
self.default_lifetime = 1.minute
belongs_to :account, :class_name => Rack::CouchdbOAuth2::Configuration.account_class.to_s
belongs_to :client
property :token, String
property :expires_at, Time
view_by :expires_at
view_by :account_id
view_by :client_id
view_by :token
before_validation :setup, :on => :create
validates :client, :expires_at, :account, :presence => true
validates :token, :presence => true, :uniqueness => true
def self.valid
view(:by_expires_at, :startkey => Time.now.utc)
end
def self.find_by_token(token)
return nil if token.nil? || token.empty?
self.first_from_view(:by_token, token)
end
end
end
|