Module: PapersPlease

Defined in:
lib/papers_please.rb,
lib/papers_please/role.rb,
lib/papers_please/errors.rb,
lib/papers_please/policy.rb,
lib/papers_please/railtie.rb,
lib/papers_please/version.rb,
lib/papers_please/permission.rb,
lib/papers_please/rails/controller_methods.rb

Defined Under Namespace

Modules: Rails Classes: AccessDenied, DuplicatePermission, DuplicateRole, DuplicateScope, Error, InvalidGrant, InvalidPermission, InvalidScope, MissingRole, Permission, Policy, Railtie, Role

Constant Summary collapse

VERSION =
'0.1.7'

Class Method Summary collapse

Class Method Details

.permissions_table(policy_klass) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/papers_please.rb', line 13

def self.permissions_table(policy_klass)
  require 'terminal-table'

  policy = policy_klass.new(:system)

  table = ::Terminal::Table.new do |t|
    t.headings = [
      'role',
      'subject',
      'permission',
      'has query?',
      'has predicate?',
      'granted by other?'
    ]

    policy.roles.each_with_index do |(name, role), index|
      t.add_separator unless index.zero?
      first_line_of_role = true

      role.permissions.group_by(&:subject).each do |subject, permissions|
        permissions.each do |permission|
          t.add_row [
            first_line_of_role ? name : nil,
            subject,
            permission.key,
            permission.query ? 'yes' : 'no',
            permission.predicate ? 'yes' : 'no',
            permission.granted_by_other? ? 'yes' : 'no'
          ]

          first_line_of_role = false
        end
      end
    end
  end

  puts table.to_s

  table.to_s
end