Class: ZuulViz
- Inherits:
-
Object
- Object
- ZuulViz
- Defined in:
- lib/zuul_viz.rb
Instance Method Summary collapse
- #graph(*args) ⇒ Object
- #graph_permission(permission, *args) ⇒ Object
- #graph_role(role, *args) ⇒ Object
- #graph_subject(subject, *args) ⇒ Object
Instance Method Details
#graph(*args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 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 53 54 |
# File 'lib/zuul_viz.rb', line 3 def graph(*args) opts = {:subject_class => Zuul.configuration.subject_class.to_s.camelize.singularize.constantize} opts = opts.merge(args[0]) if args.length > 0 subject_class = opts[:subject_class] g = GraphViz.new(:G, :type => :graph) g["compound"] = true g.edge["lhead"] = "" g.edge["ltail"] = "" #g["splines"] = "line" #g["rankdir"] = "LR" #g["nodesep"] = "2" #g["ranksep"] = "2" roles = subject_class.auth_scope.role_class.all raise "No roles to graph" if roles.length == 0 ug = g.add_graph("cluster0") ug["label"] = "Assigned #{subject_class.name.pluralize}" rg = g.add_graph("cluster1") rg["label"] = subject_class.auth_scope.role_class_name.pluralize graph_roles = {} roles.each do |role| graph_roles[role.id] = rg.add_nodes(node_str(role)) subject_class.auth_scope.role_subject_class.where(subject_class.auth_scope.role_foreign_key.to_sym => role.id).group(:context_type, :context_id).each do |role_subject| g.add_edges(graph_roles[role.id], ug.add_nodes("#{subject_class.auth_scope.role_subject_class.where(subject_class.auth_scope.role_foreign_key.to_sym => role.id, :context_type => role_subject.context_type, :context_id => role_subject.context_id).count} #{subject_class.name.pluralize}"), :label => context_str(role_subject.context), :color => context_color(role_subject.context), :fontcolor => context_color(role_subject.context)) end end = subject_class.auth_scope..all if .length > 0 = {} pg = g.add_graph("cluster2") pg["label"] = subject_class.auth_scope..pluralize .each do || [.id] = pg.add_nodes(node_str()) subject_class.auth_scope..where(subject_class.auth_scope..to_sym => .id).each do || g.add_edges(graph_roles[.send(subject_class.auth_scope.role_foreign_key.to_sym)], [.id], :label => context_str(.context), :color => context_color(.context), :fontcolor => context_color(.context)) end subject_class.auth_scope..where(subject_class.auth_scope..to_sym => .id).group(:context_type, :context_id).each do || g.add_edges([.id], ug.add_nodes("#{subject_class.auth_scope..where(subject_class.auth_scope..to_sym => .id, :context_type => .context_type, :context_id => .context_id).count} #{subject_class.name.pluralize}"), :label => context_str(.context), :color => context_color(.context), :fontcolor => context_color(.context)) end end end g end |
#graph_permission(permission, *args) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/zuul_viz.rb', line 131 def (, *args) opts = {:permission_class => Zuul.configuration..to_s.camelize.singularize.constantize} opts = opts.merge(args[0]) if args.length > 0 if .is_a?(Integer) = opts[:permission_class].find() else opts[:permission_class] = .class end g = GraphViz.new(:G, :type => :graph) g["compound"] = true g.edge["lhead"] = "" g.edge["ltail"] = "" #g["splines"] = "line" rg = g.add_graph("cluster0") rg["label"] = .auth_scope.role_class_name.pluralize ug = g.add_graph("cluster1") ug["label"] = .auth_scope.subject_class_name.pluralize = g.add_nodes(node_str()) .send(.auth_scope.).each do || role = .send(.auth_scope.role_class_name.underscore) g.add_edges(, rg.add_nodes(node_str(role)), :label => context_str(.context), :color => context_color(.context), :fontcolor => context_color(.context)) end .auth_scope..where(.auth_scope..to_sym => .id).group(:context_type, :context_id).each do || g.add_edges(, ug.add_nodes("#{.auth_scope..where(.auth_scope..to_sym => .id, :context_type => .context_type, :context_id => .context_id).count} #{.auth_scope.subject_class_name.pluralize}"), :label => context_str(.context), :color => context_color(.context), :fontcolor => context_color(.context)) end g end |
#graph_role(role, *args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/zuul_viz.rb', line 97 def graph_role(role, *args) opts = {:role_class => Zuul.configuration.role_class.to_s.camelize.singularize.constantize} opts = opts.merge(args[0]) if args.length > 0 if role.is_a?(Integer) role = opts[:role_class].find(role) else opts[:role_class] = role.class end g = GraphViz.new(:G, :type => :graph) g["compound"] = true g.edge["lhead"] = "" g.edge["ltail"] = "" #g["splines"] = "line" pg = g.add_graph("cluster0") pg["label"] = role.auth_scope..pluralize ug = g.add_graph("cluster1") ug["label"] = role.auth_scope.subject_class_name.pluralize role_node = g.add_nodes(node_str(role)) role.send(role.auth_scope.).each do || = .send(role.auth_scope..underscore) g.add_edges(role_node, pg.add_nodes(node_str()), :label => context_str(.context), :color => context_color(.context), :fontcolor => context_color(.context)) end role.auth_scope.role_subject_class.where(role.auth_scope.role_foreign_key.to_sym => role.id).group(:context_type, :context_id).each do |role_subject| g.add_edges(role_node, ug.add_nodes("#{role.auth_scope.role_subject_class.where(role.auth_scope.role_foreign_key.to_sym => role.id, :context_type => role_subject.context_type, :context_id => role_subject.context_id).count} #{role.auth_scope.subject_class_name.pluralize}"), :label => context_str(role_subject.context), :color => context_color(role_subject.context), :fontcolor => context_color(role_subject.context)) end g end |
#graph_subject(subject, *args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/zuul_viz.rb', line 56 def graph_subject(subject, *args) opts = {:subject_class => Zuul.configuration.subject_class.to_s.camelize.singularize.constantize} opts = opts.merge(args[0]) if args.length > 0 if subject.is_a?(Integer) subject = opts[:subject_class].find(subject) else opts[:subject_class] = subject.class end g = GraphViz.new(:G, :type => :graph) g["compound"] = true g.edge["lhead"] = "" g.edge["ltail"] = "" #g["splines"] = "line" rg = g.add_graph("cluster0") rg["label"] = subject.auth_scope.role_class_name.pluralize pg = g.add_graph("cluster1") pg["label"] = subject.auth_scope..pluralize subject_node = g.add_nodes("#{subject.class.name} #{subject.id}") subject.send(subject.auth_scope.role_subjects_table_name).each do |role_subject| role = role_subject.send(subject.auth_scope.role_class_name.underscore) role_node = rg.add_nodes(node_str(role)) g.add_edges(subject_node, role_node, :label => context_str(role_subject.context), :color => context_color(role_subject.context), :fontcolor => context_color(role_subject.context)) role.send(subject.auth_scope.).each do || = .send(subject.auth_scope..underscore) g.add_edges(role_node, pg.add_nodes(node_str()), :label => context_str(.context), :color => context_color(.context), :fontcolor => context_color(.context)) end end subject.send(subject.auth_scope.).each do || = .send(subject.auth_scope..underscore) g.add_edges(subject_node, pg.add_nodes(node_str()), :label => context_str(.context), :color => context_color(.context), :fontcolor => context_color(.context)) end g end |