Class: Project

Inherits:
Object
  • Object
show all
Defined in:
lib/almirah/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Project



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/almirah/project.rb', line 19

def initialize(path)
    @project_root_directory = path
    @specifications = Array.new
    @protocols = Array.new
    @traceability_matrices = Array.new
    @coverage_matrices = Array.new
    @specifications_dictionary = Hash.new
    @index = nil
    @project = self

    FileUtils.remove_dir(@project_root_directory + "/build", true)      
end

Instance Attribute Details

#coverage_matricesObject

Returns the value of attribute coverage_matrices.



13
14
15
# File 'lib/almirah/project.rb', line 13

def coverage_matrices
  @coverage_matrices
end

#indexObject

Returns the value of attribute index.



16
17
18
# File 'lib/almirah/project.rb', line 16

def index
  @index
end

#projectObject

Returns the value of attribute project.



17
18
19
# File 'lib/almirah/project.rb', line 17

def project
  @project
end

#project_root_directoryObject

Returns the value of attribute project_root_directory.



14
15
16
# File 'lib/almirah/project.rb', line 14

def project_root_directory
  @project_root_directory
end

#protocolsObject

Returns the value of attribute protocols.



11
12
13
# File 'lib/almirah/project.rb', line 11

def protocols
  @protocols
end

#specificationsObject

Returns the value of attribute specifications.



10
11
12
# File 'lib/almirah/project.rb', line 10

def specifications
  @specifications
end

#specifications_dictionaryObject

Returns the value of attribute specifications_dictionary.



15
16
17
# File 'lib/almirah/project.rb', line 15

def specifications_dictionary
  @specifications_dictionary
end

#traceability_matricesObject

Returns the value of attribute traceability_matrices.



12
13
14
# File 'lib/almirah/project.rb', line 12

def traceability_matrices
  @traceability_matrices
end

Instance Method Details

#create_indexObject



184
185
186
# File 'lib/almirah/project.rb', line 184

def create_index
    @index = Index.new( @project )
end


116
117
118
119
120
121
122
123
124
# File 'lib/almirah/project.rb', line 116

def link_all_protocols
    @protocols.each do |p|
        @specifications.each do |s|
            if p.up_link_doc_id.has_key?(s.id.to_s)
                link_protocol_to_spec(p,s)
            end
        end
    end
end


108
109
110
111
112
113
114
# File 'lib/almirah/project.rb', line 108

def link_all_specifications
    combList = @specifications.combination(2)
    combList.each do |c|
        link_two_specifications(c[0], c[1])
        # puts "Link: #{c[0].id} - #{c[1].id}"
    end
end


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/almirah/project.rb', line 161

def link_protocol_to_spec(protocol, specification)

    top_document = specification
    bottom_document = protocol

    bottom_document.controlled_items.each do |item|

        if top_document.dictionary.has_key?(item.up_link.to_s)

            topItem = top_document.dictionary[item.up_link.to_s]
            
            unless topItem.coverage_links
                topItem.coverage_links = Array.new
                top_document.items_with_coverage_number += 1    # for statistics
            end
            topItem.coverage_links.append(item)
        end
    end
    # create coverage document
    trx = Coverage.new top_document
    @coverage_matrices.append trx
end


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
# File 'lib/almirah/project.rb', line 126

def link_two_specifications(doc_A, doc_B)

    if doc_B.up_link_doc_id.has_key?(doc_A.id.to_s)
        top_document = doc_A
        bottom_document = doc_B
    elsif doc_A.up_link_doc_id.has_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|

        if item.up_link_ids
            item.up_link_ids.each do |up_lnk|

                if top_document.dictionary.has_key?(up_lnk.to_s)

                    topItem = top_document.dictionary[up_lnk.to_s]
                    
                    unless topItem.down_links
                        topItem.down_links = Array.new
                        top_document.items_with_downlinks_number += 1   # for statistics
                    end
                    topItem.down_links.append(item)
                end
            end
        end
    end
    # create treceability document
    trx = Traceability.new top_document, bottom_document, false
    @traceability_matrices.append trx
end

#parse_all_protocolsObject



92
93
94
95
96
97
98
# File 'lib/almirah/project.rb', line 92

def parse_all_protocols
    Dir.glob( "#{@project_root_directory}/tests/protocols/**/*.md" ).each do |f|
        puts "Prot: " + f
        doc = DocFabric.create_protocol(f)
        @protocols.append(doc)
    end
end

#parse_all_specificationsObject



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/almirah/project.rb', line 80

def parse_all_specifications
    # do a lasy pass first to get the list of documents id
    Dir.glob( "#{@project_root_directory}/specifications/**/*.md" ).each do |f|
        DocFabric.add_lazy_doc_id(f)
    end
    # parse documents in the second pass
    Dir.glob( "#{@project_root_directory}/specifications/**/*.md" ).each do |f|
        doc = DocFabric.create_specification(f)
        @specifications.append(doc)
    end
end

#parse_test_run(test_run) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/almirah/project.rb', line 100

def parse_test_run( test_run )
    Dir.glob( "#{@project_root_directory}/tests/runs/#{test_run}/**/*.md" ).each do |f|
        puts "Run: " + f
        doc = DocFabric.create_protocol(f)
        @protocols.append(doc)
    end
end

#render_all_protocolsObject



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/almirah/project.rb', line 214

def render_all_protocols
    
    # create a sidebar first
    # nav_pane = NavigationPane.new(@specifications)        

    pass = @project_root_directory

    # FileUtils.remove_dir(pass + "/build/tests", true)
    FileUtils.mkdir_p(pass + "/build/tests/protocols")

    @protocols.each do |doc|

        img_src_dir = pass + "/tests/protocols/" + doc.id + "/img"
        img_dst_dir = pass + "/build/tests/protocols/" + doc.id + "/img"
 
        FileUtils.mkdir_p(img_dst_dir)

        if File.directory?(img_src_dir)
            FileUtils.copy_entry( img_src_dir, img_dst_dir )
        end

        doc.to_html( nil, "#{pass}/build/tests/protocols/" )
    end
end

#render_all_specifications(spec_list) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/almirah/project.rb', line 188

def render_all_specifications(spec_list)
    
    # create a sidebar first
    # nav_pane = NavigationPane.new(@specifications)        

    pass = @project_root_directory

    FileUtils.mkdir_p(pass + "/build/specifications")

    spec_list.each do |doc|

        doc.to_console

        img_src_dir = pass + "/specifications/" + doc.id + "/img"
        img_dst_dir = pass + "/build/specifications/" + doc.id + "/img"
 
        FileUtils.mkdir_p(img_dst_dir)

        if File.directory?(img_src_dir)
            FileUtils.copy_entry( img_src_dir, img_dst_dir )
        end

        doc.to_html( nil, "#{pass}/build/specifications/" )
    end
end

#render_indexObject



239
240
241
242
243
244
245
246
247
# File 'lib/almirah/project.rb', line 239

def render_index    

    path = @project_root_directory

    doc = @index
    doc.to_console

    doc.to_html("#{path}/build/")
end

#specifications_and_protocolsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/almirah/project.rb', line 32

def specifications_and_protocols

    parse_all_specifications
    parse_all_protocols
    link_all_specifications
    link_all_protocols
    create_index
    render_all_specifications(@specifications)
    render_all_specifications(@traceability_matrices)
    render_all_specifications(@coverage_matrices)
    render_all_protocols
    render_index
end

#specifications_and_results(test_run) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/almirah/project.rb', line 46

def specifications_and_results( test_run )

    parse_all_specifications
    parse_test_run test_run
    link_all_specifications
    link_all_protocols
    create_index
    render_all_specifications(@specifications)
    render_all_specifications(@traceability_matrices)
    render_all_specifications(@coverage_matrices)
    render_all_protocols
    render_index
end

#transform(file_extension) ⇒ Object



60
61
62
# File 'lib/almirah/project.rb', line 60

def transform( file_extension )
    transform_all_specifications file_extension 
end

#transform_all_specifications(file_extension) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/almirah/project.rb', line 64

def transform_all_specifications( file_extension )

    path = @project_root_directory

    # find all specifications
    Dir.glob( "#{@project_root_directory}/specifications/**/*.md" ).each do |f|
        puts f
        # make a copy with another extention to preserve the content
        f_directory = File.dirname(f)
        f_name = File.basename(f, File.extname(f)).downcase + "._md"
        FileUtils.copy_file( f, "#{f_directory}/#{f_name}")
        # transform the original one
        # but do nothing for now - TODO
    end
end