class ShopifyAPI::Auth::AuthScopes

Constants

SCOPE_DELIMITER

Attributes

compressed_scopes[R]
expanded_scopes[R]

Public Class Methods

new(scope_names = []) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# File lib/shopify_api/auth/auth_scopes.rb, line 39
def ==(other)
  !other.nil? &&
    other.class == self.class &&
    compressed_scopes == other.compressed_scopes
end
Also aliased as: eql?
covers?(auth_scopes) click to toggle source
# File lib/shopify_api/auth/auth_scopes.rb, line 24
def covers?(auth_scopes)
  auth_scopes.compressed_scopes <= expanded_scopes
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/shopify_api/auth/auth_scopes.rb, line 48
def hash
  compressed_scopes.hash
end
to_a() click to toggle source
# File lib/shopify_api/auth/auth_scopes.rb, line 34
def to_a
  compressed_scopes.to_a
end
to_s() click to toggle source
# File lib/shopify_api/auth/auth_scopes.rb, line 29
def to_s
  to_a.join(SCOPE_DELIMITER)
end

Private Instance Methods

implied_scope(scope) click to toggle source
# File lib/shopify_api/auth/auth_scopes.rb, line 69
def implied_scope(scope)
  is_write_scope = scope =~ /\A(unauthenticated_)?write_(.*)\z/
  "#{Regexp.last_match(1)}read_#{Regexp.last_match(2)}" if is_write_scope
end
store_scopes(scope_names) click to toggle source
# File lib/shopify_api/auth/auth_scopes.rb, line 60
def store_scopes(scope_names)
  scopes = scope_names.map(&:strip).reject(&:empty?).to_set
  implied_scopes = scopes.map { |scope| implied_scope(scope) }.compact

  @compressed_scopes = scopes - implied_scopes
  @expanded_scopes = scopes + implied_scopes
end