Class: Simple::OAuth2::Scopes

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_oauth2/scopes.rb

Overview

Scopes helper for scopes validation

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_scopes, scopes = []) ⇒ Scopes

Helper class initializer

Parameters:

  • access_scopes (Array)

    scopes of AccessToken class

  • scopes (Array<String, Symbol>) (defaults to: [])

    array, symbol, string of any object that responds to ‘to_a`



19
20
21
22
# File 'lib/simple_oauth2/scopes.rb', line 19

def initialize(access_scopes, scopes = [])
  @scopes = to_array(scopes)
  @access_scopes = to_array(access_scopes)
end

Class Method Details

.valid?(access_scopes, scopes) ⇒ Boolean

Checks if requested scopes are valid

Parameters:

  • access_scopes (Array)

    scopes of AccessToken class

  • scopes (Array<String, Symbol>)

    array, symbol, string of any object that responds to ‘to_a`

Returns:

  • (Boolean)


10
11
12
# File 'lib/simple_oauth2/scopes.rb', line 10

def self.valid?(access_scopes, scopes)
  new(access_scopes, scopes).valid?
end

Instance Method Details

#valid?Boolean

Checks if requested scopes (passed and processed on initialization) are presented in the AccessToken

Returns:

  • (Boolean)

    true if requested scopes are empty or present in access_scopes



28
29
30
# File 'lib/simple_oauth2/scopes.rb', line 28

def valid?
  @scopes.empty? || present_in_access_token?
end