Class: GrantFront::Diagram

Inherits:
Object
  • Object
show all
Defined in:
lib/grant-front/diagram.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Diagram

Returns a new instance of Diagram.



9
10
11
# File 'lib/grant-front/diagram.rb', line 9

def initialize(options={})
  @options = options
end

Class Method Details

.draw(options = {}) ⇒ Object



4
5
6
# File 'lib/grant-front/diagram.rb', line 4

def draw(options={})
  puts self.new(options).create
end

Instance Method Details

#createObject



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
# File 'lib/grant-front/diagram.rb', line 13

def create
  policies = []
  GrantFront::Policy.all(@options).each do |policy|
    if @options[:classes].nil? or @options[:classes].include?(policy.klass)
      policies << GrantFront::Policy.find(policy.klass)
    end
  end

  text = ''
  policies.each do |policy|
    text += "\n### #{policy.name}\n\n"
    if policy.roles.count > 0
      text += "||#{policy.roles.join('|')}|\n"
      text += "|:-|#{policy.roles.map{':-:'}.join('|')}|\n"
      policy.methods.keys.each do |method|
        raw = "|#{method}|"
        policy.roles.each do |role|
          raw += 'o' if policy.methods[method].include?(role)
          raw += '|'
        end
        text += "#{raw}\n"
      end
    else
      text += "* no policy\n"
    end
  end
  text
end