Class: WebViewTransformer
- Inherits:
-
Object
- Object
- WebViewTransformer
- Defined in:
- lib/audit/lib/transformers/web_view_transformer.rb
Constant Summary collapse
- IMAGE_PREFIX =
"/images"
- BENCHMARK_ID =
"BENCHMARK"
- @@LOG =
Logger.new(STDOUT)
Class Method Summary collapse
Class Method Details
.get(audit, id) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/audit/lib/transformers/web_view_transformer.rb', line 17 def self.get(audit, id) if (id == :root) then item = audit.benchmark return { 'data' => { 'title' => item.name || item.id, 'attr' => {}, 'icon' => 'folder'}, 'attr' => { 'id' => BENCHMARK_ID}, 'state' => 'closed'} else return self.get_children(audit, id) end end |
.get_children(audit, id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/audit/lib/transformers/web_view_transformer.rb', line 33 def self.get_children(audit, id) if id == BENCHMARK_ID then item = audit.benchmark else item = audit.results[id] || audit.benchmark.item_repository[id] end if item.kind_of? AuditBenchmark then return item.children.map {|x| self.get_item(audit, x.id)} elsif item.kind_of? Group then return item.children.map {|x| self.get_item(audit, x.id)} elsif item.kind_of? RuleResult then if item.rule.description then results = [{ 'data' => { 'title' => item.rule.description, 'icon' => "#{IMAGE_PREFIX}/tag_blue.png"}, 'state' => 'opened', 'children' => [] }] else results = [] end results = results + item.check.reject do|x| x.methods.include?(:visible?) && (!x.visible?()) end.map do |x| case x.type when ResultType::MESSAGE then { 'data' => { 'title' => x.to_string(), 'icon' => "#{IMAGE_PREFIX}/script.png"}, 'state' => 'opened', 'children' => [] } when ResultType::DATA then { 'data' => { 'title' => x.to_string(), 'icon' => "#{IMAGE_PREFIX}/brick.png"}, 'state' => 'opened', 'children' => [] } when ResultType::PROGRAM_NAME then { 'data' => { 'title' => x.to_string(), 'icon' => "#{IMAGE_PREFIX}/cog.png"}, 'state' => 'opened', 'children' => [] } else { 'data' => { 'title' => x.to_string(), 'icon' => "file"}, 'state' => 'opened', 'children' => [] } end end return results elsif item.kind_of? Check then #check was not executed, thus no result if item.description then return [{ 'data' => { 'title' => item.description, 'icon' => "#{IMAGE_PREFIX}/tag_blue.png"}, 'state' => 'opened', 'children' => [] }] else return [] end else raise "Unknown item type #{item.class.name}" end end |
.get_item(audit, id) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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 164 165 166 167 168 |
# File 'lib/audit/lib/transformers/web_view_transformer.rb', line 115 def self.get_item(audit, id) item = audit.results[id] || audit.benchmark.item_repository[id] if item.kind_of? AuditBenchmark then return { 'data' => { 'title' => item.name || item.id, 'icon' => 'folder'}, 'attr' => {'id' => 'BENCHMARK'}, 'state' => 'closed'} elsif item.kind_of? Group then return { 'data' => { 'title' => item.name || item.id, 'icon' => 'folder'}, 'attr' => {'id' => item.id}, 'state' => 'closed'} elsif item.kind_of? RuleResult then return { 'data' => { 'title' => item.rule.name || item.rule.id, 'icon' => case item.result when ResultCode::PASS then "#{IMAGE_PREFIX}/tick.png" when ResultCode::FAIL then if (item.severity == RuleSeverity::LOW || item.severity == RuleSeverity::INFO) then "#{IMAGE_PREFIX}/warning.png" else "#{IMAGE_PREFIX}/fail.png" end else "#{IMAGE_PREFIX}/question.png" end}, 'attr' => { 'id' => item.rule.id}, 'state' => 'closed'} elsif item.kind_of? Check then if item.description then return { 'data' => { 'title' => item.name || item.id, 'icon' => "#{IMAGE_PREFIX}/hourglass.png"}, 'attr' => {'id' => item.id}, 'state' => 'closed'} else return { 'data' => { 'title' => item.name || item.id, 'icon' => "#{IMAGE_PREFIX}/hourglass.png"}, 'attr' => {'id' => item.id}, 'state' => 'opened', 'children' => []} end else raise "Unknown item type #{item.class.name} for id #{id}" end end |