Module: Devise::Oauth::Scopable::ClassMethods

Defined in:
lib/devise/oauth/scopable.rb

Instance Method Summary collapse

Instance Method Details

#mask_to_scope(mask) ⇒ Object



30
31
32
33
# File 'lib/devise/oauth/scopable.rb', line 30

def mask_to_scope(mask)
  return [] if mask == 0
  scopes.reject {|r| (mask & 2**scopes.index(r)).zero? }
end

#scope_to_mask(scope = []) ⇒ Object



25
26
27
28
# File 'lib/devise/oauth/scopable.rb', line 25

def scope_to_mask(scope=[])
  return 0 if scope.blank?
  (scope.map(&:to_s) & scopes).map { |r| 2**scopes.index(r) }.sum
end

#scopesObject



21
22
23
# File 'lib/devise/oauth/scopable.rb', line 21

def scopes
  @@scopes ||= Devise::Oauth.scopes.map {|s| s.to_s}
end

#where_scope(scope = []) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/devise/oauth/scopable.rb', line 35

def where_scope(scope=[])
  if scope.blank?
    where "scope_mask = 0"
  else
    where "scope_mask & ? > 0", scope_to_mask(scope)
  end
end