Class: GoogleSAAuth::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/google-sa-auth/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Scope

Returns a new instance of Scope.



6
7
8
# File 'lib/google-sa-auth/scope.rb', line 6

def initialize(name)
  get_api_info(name.to_s)
end

Instance Attribute Details

#api_infoObject

Returns the value of attribute api_info.



5
6
7
# File 'lib/google-sa-auth/scope.rb', line 5

def api_info
  @api_info
end

#scope_urlsObject

Returns the value of attribute scope_urls.



5
6
7
# File 'lib/google-sa-auth/scope.rb', line 5

def scope_urls
  @scope_urls
end

Instance Method Details

#by_extension(extension) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/google-sa-auth/scope.rb', line 24

def by_extension(extension)
  # If extension is nil, then we can just return full access.
  return full_access if extension.nil?

  # Try to find a scope by extension, e.g. ".readonly"
  self.scope_urls.each do |url|
    return url if url =~ /\.#{extension}$/i
  end
  nil
end

#full_accessObject



14
15
16
17
# File 'lib/google-sa-auth/scope.rb', line 14

def full_access
  # Get the shortest scope, which theoretically will be full permissions.
  self.scope_urls.sort_by {|url| url.length}.first
end

#read_onlyObject



19
20
21
22
# File 'lib/google-sa-auth/scope.rb', line 19

def read_only
  # Simply wrapper for .readonly permissions.
  by_extension('readonly')
end

#urlObject



10
11
12
# File 'lib/google-sa-auth/scope.rb', line 10

def url
  full_access
end