Class: Project
- Inherits:
-
Object
- Object
- Project
- Defined in:
- lib/almirah/project.rb
Overview
rubocop:disable Metrics/ClassLength,Style/Documentation
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#coverage_matrices ⇒ Object
Returns the value of attribute coverage_matrices.
-
#index ⇒ Object
Returns the value of attribute index.
-
#project ⇒ Object
Returns the value of attribute project.
-
#protocols ⇒ Object
Returns the value of attribute protocols.
-
#specifications ⇒ Object
Returns the value of attribute specifications.
-
#specifications_dictionary ⇒ Object
Returns the value of attribute specifications_dictionary.
-
#traceability_matrices ⇒ Object
Returns the value of attribute traceability_matrices.
Instance Method Summary collapse
-
#check_wrong_specification_referenced ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #copy_resources ⇒ Object
- #create_index ⇒ Object
- #create_search_data ⇒ Object
-
#initialize(configuration) ⇒ Project
constructor
A new instance of Project.
-
#link_all_protocols ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#link_all_specifications ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#link_protocol_to_spec(protocol, specification) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
-
#link_two_specifications(doc_a, doc_b) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #parse_all_protocols ⇒ Object
- #parse_all_specifications ⇒ Object
- #parse_test_run(test_run) ⇒ Object
- #render_all_protocols ⇒ Object
-
#render_all_specifications(spec_list) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #render_index ⇒ Object
-
#specifications_and_protocols ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#specifications_and_results(test_run) ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(configuration) ⇒ Project
Returns a new instance of Project.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/almirah/project.rb', line 14 def initialize(configuration) @configuration = configuration @specifications = [] @protocols = [] @traceability_matrices = [] @coverage_matrices = [] @specifications_dictionary = {} @covered_specifications_dictionary = {} @index = nil @project = self FileUtils.remove_dir("#{@configuration.project_root_directory}/build", true) copy_resources end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def configuration @configuration end |
#coverage_matrices ⇒ Object
Returns the value of attribute coverage_matrices.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def coverage_matrices @coverage_matrices end |
#index ⇒ Object
Returns the value of attribute index.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def index @index end |
#project ⇒ Object
Returns the value of attribute project.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def project @project end |
#protocols ⇒ Object
Returns the value of attribute protocols.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def protocols @protocols end |
#specifications ⇒ Object
Returns the value of attribute specifications.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def specifications @specifications end |
#specifications_dictionary ⇒ Object
Returns the value of attribute specifications_dictionary.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def specifications_dictionary @specifications_dictionary end |
#traceability_matrices ⇒ Object
Returns the value of attribute traceability_matrices.
11 12 13 |
# File 'lib/almirah/project.rb', line 11 def traceability_matrices @traceability_matrices end |
Instance Method Details
#check_wrong_specification_referenced ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
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 |
# File 'lib/almirah/project.rb', line 136 def check_wrong_specification_referenced # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity available_specification_ids = {} @specifications.each do |s| available_specification_ids[s.id.to_s.downcase] = s end @specifications.each do |s| # rubocop:disable Style/CombinableLoops s.up_link_docs.each do |key, _value| next if available_specification_ids.key?(key) # now key points to the doc_id that does not exist wrong_doc_id = key # find the item that reference to it s.controlled_items.each do |item| next if item.up_link_ids.nil? item.up_link_ids.each do |up_link_id| next unless tmp = /^([a-zA-Z]+)-\d+/.match(up_link_id) # SRS if tmp[1].downcase == wrong_doc_id # we got it finally! s.wrong_links_hash[up_link_id.to_s] = item end end end end end end |
#copy_resources ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/almirah/project.rb', line 28 def copy_resources # scripts gem_root = File. './../..', File.dirname(__FILE__) src_folder = "#{gem_root}/lib/almirah/templates/scripts" dst_folder = "#{@configuration.project_root_directory}/build/scripts" FileUtils.mkdir_p(dst_folder) FileUtils.copy_entry(src_folder, dst_folder) # css src_folder = "#{gem_root}/lib/almirah/templates/css" dst_folder = "#{@configuration.project_root_directory}/build/css" FileUtils.mkdir_p(dst_folder) FileUtils.copy_entry(src_folder, dst_folder) end |
#create_index ⇒ Object
230 231 232 |
# File 'lib/almirah/project.rb', line 230 def create_index @index = Index.new(@project) end |
#create_search_data ⇒ Object
281 282 283 284 285 286 |
# File 'lib/almirah/project.rb', line 281 def create_search_data db = SpecificationsDb.new @specifications data_path = "#{@configuration.project_root_directory}/build/data" FileUtils.mkdir_p(data_path) db.save(data_path) end |
#link_all_protocols ⇒ Object
rubocop:disable Metrics/MethodLength
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/almirah/project.rb', line 120 def link_all_protocols # rubocop:disable Metrics/MethodLength @protocols.each do |p| @specifications.each do |s| if p.up_link_docs.key?(s.id.to_s) link_protocol_to_spec(p, s) @covered_specifications_dictionary[s.id.to_s] = s end end end # create coverage documents @covered_specifications_dictionary.each do |_key, value| doc = DocFabric.create_coverage_matrix(value) @coverage_matrices.append doc end end |
#link_all_specifications ⇒ Object
rubocop:disable Metrics/MethodLength
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/almirah/project.rb', line 102 def link_all_specifications # rubocop:disable Metrics/MethodLength comb_list = @specifications.combination(2) comb_list.each do |c| link_two_specifications(c[0], c[1]) # puts "Link: #{c[0].id} - #{c[1].id}" end # separatelly create design inputs treceability @configuration.get_design_inputs.each do |i| next unless @specifications_dictionary.key? i.to_s.downcase document = @specifications_dictionary[i.to_s.downcase] if document doc = DocFabric.create_traceability_document(document, nil) @traceability_matrices.append doc end end end |
#link_protocol_to_spec(protocol, specification) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/almirah/project.rb', line 203 def link_protocol_to_spec(protocol, specification) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity top_document = specification bottom_document = protocol bottom_document.controlled_items.each do |item| next unless item.up_link_ids item.up_link_ids.each do |up_lnk| if top_document.dictionary.key?(up_lnk.to_s) top_item = top_document.dictionary[up_lnk.to_s] unless top_item.coverage_links top_item.coverage_links = [] top_document.items_with_coverage_number += 1 # for statistics end top_item.coverage_links.append(item) elsif tmp = /^([a-zA-Z]+)-\d+/.match(up_lnk) # check if there is a non existing link with the right doc_id if tmp[1].downcase == top_document.id.downcase bottom_document.wrong_links_hash[up_lnk] = item end # SRS end end end end |
#link_two_specifications(doc_a, doc_b) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/almirah/project.rb', line 166 def link_two_specifications(doc_a, doc_b) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity if doc_b.up_link_docs.key?(doc_a.id.to_s) top_document = doc_a bottom_document = doc_b elsif doc_a.up_link_docs.key?(doc_b.id.to_s) top_document = doc_b bottom_document = doc_a else return # no links end # puts "Link: #{doc_a.id} - #{doc_b.id}" bottom_document.controlled_items.each do |item| next unless item.up_link_ids item.up_link_ids.each do |up_lnk| if top_document.dictionary.key?(up_lnk.to_s) top_item = top_document.dictionary[up_lnk.to_s] unless top_item.down_links top_item.down_links = [] top_document.items_with_downlinks_number += 1 # for statistics end top_item.down_links.append(item) elsif tmp = /^([a-zA-Z]+)-\d+/.match(up_lnk) # check if there is a non existing link with the right doc_id if tmp[1].downcase == top_document.id.downcase bottom_document.wrong_links_hash[up_lnk] = item end # SRS end end end # create treceability document doc = DocFabric.create_traceability_document(top_document, bottom_document) @traceability_matrices.append doc end |
#parse_all_protocols ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/almirah/project.rb', line 86 def parse_all_protocols path = @configuration.project_root_directory Dir.glob("#{path}/tests/protocols/**/*.md").each do |f| doc = DocFabric.create_protocol(f) @protocols.append(doc) end end |
#parse_all_specifications ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/almirah/project.rb', line 72 def parse_all_specifications path = @configuration.project_root_directory # do a lasy pass first to get the list of documents id Dir.glob("#{path}/specifications/**/*.md").each do |f| DocFabric.add_lazy_doc_id(f) end # parse documents in the second pass Dir.glob("#{path}/specifications/**/*.md").each do |f| # rubocop:disable Style/CombinableLoops doc = DocFabric.create_specification(f) @specifications.append(doc) @specifications_dictionary[doc.id.to_s.downcase] = doc end end |
#parse_test_run(test_run) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/almirah/project.rb', line 94 def parse_test_run(test_run) path = @configuration.project_root_directory Dir.glob("#{path}/tests/runs/#{test_run}/**/*.md").each do |f| doc = DocFabric.create_protocol(f) @protocols.append(doc) end end |
#render_all_protocols ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/almirah/project.rb', line 254 def render_all_protocols path = @configuration.project_root_directory FileUtils.mkdir_p("#{path}/build/tests/protocols") @protocols.each do |doc| img_src_dir = "#{path}/tests/protocols/#{doc.id}/img" img_dst_dir = "#{path}/build/tests/protocols/#{doc.id}/img" FileUtils.mkdir_p(img_dst_dir) FileUtils.copy_entry(img_src_dir, img_dst_dir) if File.directory?(img_src_dir) nav_pane = NavigationPane.new(doc) doc.to_html(nav_pane, "#{path}/build/tests/protocols/") end end |
#render_all_specifications(spec_list) ⇒ Object
rubocop:disable Metrics/MethodLength
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/almirah/project.rb', line 234 def render_all_specifications(spec_list) # rubocop:disable Metrics/MethodLength path = @configuration.project_root_directory FileUtils.mkdir_p("#{path}/build/specifications") spec_list.each do |doc| doc.to_console img_src_dir = "#{path}/specifications/#{doc.id}/img" img_dst_dir = "#{path}/build/specifications/#{doc.id}/img" FileUtils.mkdir_p(img_dst_dir) FileUtils.copy_entry(img_src_dir, img_dst_dir) if File.directory?(img_src_dir) nav_pane = NavigationPane.new(doc) doc.to_html(nav_pane, "#{path}/build/specifications/") end end |
#render_index ⇒ Object
272 273 274 275 276 277 278 279 |
# File 'lib/almirah/project.rb', line 272 def render_index path = @configuration.project_root_directory doc = @index doc.to_console doc.to_html("#{path}/build/") end |
#specifications_and_protocols ⇒ Object
rubocop:disable Metrics/MethodLength
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/almirah/project.rb', line 42 def specifications_and_protocols # rubocop:disable Metrics/MethodLength parse_all_specifications parse_all_protocols link_all_specifications link_all_protocols check_wrong_specification_referenced create_index render_all_specifications(@specifications) render_all_specifications(@traceability_matrices) render_all_specifications(@coverage_matrices) render_all_protocols render_index create_search_data end |
#specifications_and_results(test_run) ⇒ Object
rubocop:disable Metrics/MethodLength
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/almirah/project.rb', line 57 def specifications_and_results(test_run) # rubocop:disable Metrics/MethodLength parse_all_specifications parse_test_run test_run link_all_specifications link_all_protocols check_wrong_specification_referenced create_index render_all_specifications(@specifications) render_all_specifications(@traceability_matrices) render_all_specifications(@coverage_matrices) render_all_protocols render_index create_search_data end |