Class: ShopifyAPI::Auth::AuthScopes

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/shopify_api/auth/auth_scopes.rb

Constant Summary collapse

SCOPE_DELIMITER =
","

Instance Method Summary collapse

Constructor Details

#initialize(scope_names = []) ⇒ AuthScopes

Returns a new instance of AuthScopes.


12
13
14
15
16
17
18
19
20
21
# File 'lib/shopify_api/auth/auth_scopes.rb', line 12

def initialize(scope_names = [])
  @compressed_scopes = T.let([].to_set, T::Set[String])
  @expanded_scopes = T.let([].to_set, T::Set[String])

  if scope_names.is_a?(String)
    scope_names = scope_names.to_s.split(SCOPE_DELIMITER)
  end

  store_scopes(scope_names)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?


39
40
41
42
43
# File 'lib/shopify_api/auth/auth_scopes.rb', line 39

def ==(other)
  !other.nil? &&
    other.class == self.class &&
    compressed_scopes == other.compressed_scopes
end

#covers?(auth_scopes) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/shopify_api/auth/auth_scopes.rb', line 24

def covers?(auth_scopes)
  auth_scopes.compressed_scopes <= expanded_scopes
end

#hashObject


48
49
50
# File 'lib/shopify_api/auth/auth_scopes.rb', line 48

def hash
  compressed_scopes.hash
end

#to_aObject


34
35
36
# File 'lib/shopify_api/auth/auth_scopes.rb', line 34

def to_a
  compressed_scopes.to_a
end

#to_sObject


29
30
31
# File 'lib/shopify_api/auth/auth_scopes.rb', line 29

def to_s
  to_a.join(SCOPE_DELIMITER)
end