Class: Cassette::Authentication::Authorities

Inherits:
Object
  • Object
show all
Defined in:
lib/cassette/authentication/authorities.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorities, base_authority = nil) ⇒ Authorities



26
27
28
29
30
31
32
33
34
# File 'lib/cassette/authentication/authorities.rb', line 26

def initialize(authorities, base_authority = nil)
  @base_authority = base_authority || Cassette.config.base_authority

  if authorities.is_a?(String)
    @authorities = authorities.gsub(/^\[(.*)\]$/, '\\1').split(',').map(&:strip)
  else
    @authorities = Array(authorities).map(&:strip)
  end
end

Class Method Details

.parse(authorities, base_authority = nil) ⇒ Object



8
9
10
# File 'lib/cassette/authentication/authorities.rb', line 8

def self.parse(authorities, base_authority = nil)
  new(authorities, base_authority)
end

Instance Method Details

#authoritiesObject



36
37
38
# File 'lib/cassette/authentication/authorities.rb', line 36

def authorities
  @authorities.dup
end

#baseObject



12
13
14
# File 'lib/cassette/authentication/authorities.rb', line 12

def base
  @base_authority.to_s.upcase
end

#has_raw_role?(role) ⇒ Boolean



16
17
18
19
# File 'lib/cassette/authentication/authorities.rb', line 16

def has_raw_role?(role)
  return true if ENV['NOAUTH']
  @authorities.include?(role)
end

#has_role?(role) ⇒ Boolean



21
22
23
24
# File 'lib/cassette/authentication/authorities.rb', line 21

def has_role?(role)
  return true if ENV['NOAUTH']
  has_raw_role?("#{base}_#{role.to_s.upcase.gsub('_', '-')}")
end