Class: Aptible::Auth::Role
- Defined in:
- lib/aptible/auth/role.rb
Instance Method Summary collapse
- #account_permissions(account) ⇒ Object
- #add_account_scope(account, scope) ⇒ Object
- #add_account_scopes(account, scopes) ⇒ Object
- #permissions ⇒ Object
- #set_account_permissions(account, scopes) ⇒ Object
- #users ⇒ Object
Methods inherited from Resource
Instance Method Details
#account_permissions(account) ⇒ Object
28 29 30 31 32 |
# File 'lib/aptible/auth/role.rb', line 28 def (account) account..select do || (link = .links[:role]) && link.href == href end end |
#add_account_scope(account, scope) ⇒ Object
38 39 40 |
# File 'lib/aptible/auth/role.rb', line 38 def add_account_scope(account, scope) account.(scope: scope, role: href) end |
#add_account_scopes(account, scopes) ⇒ Object
34 35 36 |
# File 'lib/aptible/auth/role.rb', line 34 def add_account_scopes(account, scopes) scopes.each { |scope| add_account_scope(account, scope) } end |
#permissions ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/aptible/auth/role.rb', line 42 def require 'aptible/api' = Aptible::Api::Permission.all(token: token, headers: headers) .select do || (link = .links[:role]) && link.href == href end end |
#set_account_permissions(account, scopes) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/aptible/auth/role.rb', line 18 def (account, scopes) = (account) .each { |p| p.destroy unless scopes.include? p.scope } existing = .keep_if { |p| scopes.include? p.scope } new_scopes = scopes - existing.map(&:scope) add_account_scopes(account, new_scopes) end |
#users ⇒ Object
14 15 16 |
# File 'lib/aptible/auth/role.rb', line 14 def users @users ||= memberships.map(&:user).uniq end |