defmastership 1.0.7 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/bin/defmastership +1 -1
  4. data/features/changeref.feature +33 -0
  5. data/features/{checksum.feature → definition_checksum.feature} +85 -31
  6. data/features/definition_version.feature +204 -0
  7. data/features/export.feature +21 -21
  8. data/features/modify.feature +23 -1
  9. data/features/rename_included_files.feature +4 -0
  10. data/lib/defmastership.rb +3 -0
  11. data/lib/defmastership/batch_modifier.rb +2 -0
  12. data/lib/defmastership/change_ref_line_modifier.rb +2 -1
  13. data/lib/defmastership/constants.rb +4 -2
  14. data/lib/defmastership/csv_formatter.rb +12 -6
  15. data/lib/defmastership/csv_formatter_body.rb +8 -5
  16. data/lib/defmastership/csv_formatter_header.rb +5 -1
  17. data/lib/defmastership/definition.rb +4 -4
  18. data/lib/defmastership/document.rb +11 -15
  19. data/lib/defmastership/rename_included_files_line_modifier.rb +1 -1
  20. data/lib/defmastership/update_def_checksum_line_modifier.rb +2 -3
  21. data/lib/defmastership/update_def_checksum_modifier.rb +1 -1
  22. data/lib/defmastership/update_def_version_line_modifier.rb +58 -0
  23. data/lib/defmastership/update_def_version_modifier.rb +25 -0
  24. data/lib/defmastership/version.rb +1 -1
  25. data/spec/unit/defmastership/batch_modifier_spec.rb +8 -0
  26. data/spec/unit/defmastership/change_ref_line_modifier_spec.rb +15 -0
  27. data/spec/unit/defmastership/csv_formatter_body_spec.rb +42 -60
  28. data/spec/unit/defmastership/csv_formatter_header_spec.rb +23 -1
  29. data/spec/unit/defmastership/csv_formatter_spec.rb +204 -67
  30. data/spec/unit/defmastership/definition_spec.rb +19 -4
  31. data/spec/unit/defmastership/document_spec.rb +71 -4
  32. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +8 -8
  33. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +14 -4
  34. data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +127 -0
  35. data/spec/unit/defmastership/update_def_version_modifier_spec.rb +80 -0
  36. metadata +8 -3
@@ -15,9 +15,9 @@ Feature: The extract command
15
15
  When I successfully run `defmastership export toto.adoc`
16
16
  Then the file "toto.csv" should contain:
17
17
  """
18
- Type,Reference,Value,sha256
18
+ Type,Reference,Value,Checksum
19
19
  requirement,TOTO-0001,"Exemple of multiline requirement.
20
- Second line.",b86dcbde
20
+ Second line.",~b86dcbde
21
21
  """
22
22
  And the stdout should not contain anything
23
23
  And the stderr should not contain anything
@@ -34,9 +34,9 @@ Feature: The extract command
34
34
  When I successfully run `defmastership export --separator=';' toto.adoc`
35
35
  Then the file "toto.csv" should contain:
36
36
  """
37
- Type;Reference;Value;sha256
37
+ Type;Reference;Value;Checksum
38
38
  requirement;TOTO-0001;"Exemple of multiline requirement.
39
- Second line.";b86dcbde
39
+ Second line.";~b86dcbde
40
40
  """
41
41
 
42
42
  Scenario: Extract one definition with variable to CSV
@@ -54,10 +54,10 @@ Feature: The extract command
54
54
  When I successfully run `defmastership export toto.adoc`
55
55
  Then the file "toto.csv" should contain:
56
56
  """
57
- Type,Reference,Value,sha256
57
+ Type,Reference,Value,Checksum
58
58
  requirement,TOTO-0001,"Exemple of multiline requirement with variable: Variable content.
59
59
  Variable content : Variable content Toto.
60
- Third line with {not_defined_variable}.",3bf370ed
60
+ Third line with {not_defined_variable}.",~3bf370ed
61
61
  """
62
62
  And the stdout should not contain anything
63
63
  And the stderr should not contain anything
@@ -82,11 +82,11 @@ Feature: The extract command
82
82
  When I successfully run `defmastership export toto.adoc`
83
83
  Then the file "toto.csv" should contain:
84
84
  """
85
- Type,Reference,Value,sha256
85
+ Type,Reference,Value,Checksum
86
86
  requirement,TOTO-0001,"Exemple of multiline requirement.
87
- Second line.",b86dcbde
87
+ Second line.",~b86dcbde
88
88
  something_else,TOTO-0003,"only one paragraphe.
89
- with two sentences.",4761e172
89
+ with two sentences.",~4761e172
90
90
  """
91
91
  And the file "toto.csv" should not contain:
92
92
  """
@@ -172,9 +172,9 @@ Feature: The extract command
172
172
  When I successfully run `defmastership export toto.adoc`
173
173
  Then the file "toto.csv" should contain:
174
174
  """
175
- Type,Reference,Value,sha256,Labels
175
+ Type,Reference,Value,Checksum,Labels
176
176
  requirement,TOTO-0001,"Exemple of multiline requirement.
177
- Second line.",b86dcbde,"label1
177
+ Second line.",~b86dcbde,"label1
178
178
  label2"
179
179
  """
180
180
  And the stdout should not contain anything
@@ -195,9 +195,9 @@ Feature: The extract command
195
195
  When I successfully run `defmastership export toto.adoc`
196
196
  Then the file "toto.csv" should contain:
197
197
  """
198
- Type,Reference,Value,sha256,Participate to:
198
+ Type,Reference,Value,Checksum,Participate to:
199
199
  requirement,TOTO-0001,"Exemple of multiline requirement.
200
- Second line.",b86dcbde,"SYSTEM-0012
200
+ Second line.",~b86dcbde,"SYSTEM-0012
201
201
  SYSTEM-0014"
202
202
  """
203
203
  And the stdout should not contain anything
@@ -218,9 +218,9 @@ Feature: The extract command
218
218
  When I successfully run `defmastership export toto.adoc`
219
219
  Then the file "toto.csv" should contain:
220
220
  """
221
- Type,Reference,Value,sha256,Participate to:
221
+ Type,Reference,Value,Checksum,Participate to:
222
222
  requirement,TOTO-0001,"Exemple of multiline requirement.
223
- Second line.",b86dcbde,"SYSTEM-0012
223
+ Second line.",~b86dcbde,"SYSTEM-0012
224
224
  SYSTEM-0014"
225
225
  """
226
226
  And the stdout should not contain anything
@@ -242,9 +242,9 @@ Feature: The extract command
242
242
  And the stderr should not contain anything
243
243
  And the file "toto.csv" should contain:
244
244
  """
245
- Type,Reference,Value,sha256,Participate to:
245
+ Type,Reference,Value,Checksum,Participate to:
246
246
  requirement,TOTO-0001,"Exemple of multiline requirement.
247
- Second line.",b86dcbde,"SYSTEM-0012
247
+ Second line.",~b86dcbde,"SYSTEM-0012
248
248
  SYSTEM-0014"
249
249
  """
250
250
 
@@ -261,9 +261,9 @@ Feature: The extract command
261
261
  When I successfully run `defmastership export toto.adoc`
262
262
  Then the file "toto.csv" should contain:
263
263
  """
264
- Type,Reference,Value,sha256,Internal links
264
+ Type,Reference,Value,Checksum,Internal links
265
265
  requirement,TOTO-0001,"Exemple of multiline requirement.
266
- Second line: defs:iref[TOTO-0001], defs:iref[TOTO-0123].",059b7188,"TOTO-0001
266
+ Second line: defs:iref[TOTO-0001], defs:iref[TOTO-0123].",~059b7188,"TOTO-0001
267
267
  TOTO-0123
268
268
  TOTO-0002"
269
269
  """
@@ -286,8 +286,8 @@ Feature: The extract command
286
286
  And the stdout should not contain anything
287
287
  Then the file "toto.csv" should contain:
288
288
  """
289
- Type,Reference,Value,sha256,Verified by:,Criticity:
290
- requirement,TOTO-0001,One single line.,554b0ff5,Beautiful Test,Very cool
289
+ Type,Reference,Value,Checksum,Verified by:,Criticity:
290
+ requirement,TOTO-0001,One single line.,~554b0ff5,Beautiful Test,Very cool
291
291
  """
292
292
  And the stdout should not contain anything
293
293
  And the stderr should not contain anything
@@ -3,7 +3,7 @@ Feature: The modify command
3
3
  In order to manage to applu predefined modifications
4
4
  I want defmastership to apply automatic modifications
5
5
 
6
- Scenario: Change one modifier
6
+ Scenario: Changes with one modifier
7
7
  Given a file named "modifications.yml" with:
8
8
  """
9
9
  ---
@@ -36,6 +36,28 @@ Feature: The modify command
36
36
  [define, requirement, TOTO-0123]
37
37
  """
38
38
 
39
+
40
+ Scenario: Change with wrong modifier
41
+ Given a file named "modifications.yml" with:
42
+ """
43
+ ---
44
+ :temp-references:
45
+ :type: change_ref
46
+ :config:
47
+ :from_regexp: TOTO-TEMP-[X\d]{4}
48
+ :to_template: TOTO-%<next_ref>04d
49
+ :next_ref: 123
50
+ """
51
+ And a file named "thedoc.adoc" with:
52
+ """
53
+ [define, requirement, TOTO-TEMP-XXX1]
54
+ """
55
+ When I run `defmastership modify --modifications wrong-modification thedoc.adoc`
56
+ Then it should fail with:
57
+ """
58
+ error: wrong-modification is not a known modification
59
+ """
60
+
39
61
  Scenario: Make modifications with yaml file parameter
40
62
  Given a file named "pouet.yml" with:
41
63
  """
@@ -73,7 +73,9 @@ Feature: The rename_included_files command
73
73
  :any: one
74
74
  :path: two
75
75
  [define, requirement, TOTO-WHATEVER-123]
76
+ --
76
77
  include::{any}_{path}/one_file.png[]
78
+ --
77
79
  """
78
80
  And a directory named "one_two"
79
81
  And an empty file named "one_two/one_file.png"
@@ -85,7 +87,9 @@ Feature: The rename_included_files command
85
87
  :any: one
86
88
  :path: two
87
89
  [define, requirement, TOTO-WHATEVER-123]
90
+ --
88
91
  include::{any}_{path}/TOTO-WHATEVER-123_one_file.png[]
92
+ --
89
93
  """
90
94
  And the file "one_two/one_file.png" should not exist
91
95
  And the file "one_two/TOTO-WHATEVER-123_one_file.png" should exist
data/lib/defmastership.rb CHANGED
@@ -25,3 +25,6 @@ require('defmastership/rename_included_files_line_modifier')
25
25
 
26
26
  require('defmastership/update_def_checksum_modifier')
27
27
  require('defmastership/update_def_checksum_line_modifier')
28
+
29
+ require('defmastership/update_def_version_modifier')
30
+ require('defmastership/update_def_version_line_modifier')
@@ -26,6 +26,8 @@ module DefMastership
26
26
  private
27
27
 
28
28
  def modifier_from(modif)
29
+ raise(ArgumentError, "#{modif} is not a known modification") if @config[modif.to_sym].nil?
30
+
29
31
  class_name = "#{@config[modif.to_sym][:type].split('_').map(&:capitalize).join}Modifier"
30
32
  DefMastership.const_get(class_name).new(@config[modif.to_sym][:config])
31
33
  end
@@ -66,12 +66,13 @@ module DefMastership
66
66
  regexp_str =
67
67
  "(?<before>#{REGEXP_FROM[const][:before]})" \
68
68
  "(?<from>#{from})" \
69
+ "#{DMRegexp::DEF_VERSION_AND_CHECKSUM}" \
69
70
  "(?<after>#{REGEXP_FROM[const][:after]})"
70
71
  Regexp.new(regexp_str, Regexp::EXTENDED)
71
72
  end
72
73
 
73
74
  def text_with(match, replacement)
74
- match[:before] + replacement + match[:after]
75
+ match[:before] + replacement + (match[:version_and_checksum] || '') + match[:after]
75
76
  end
76
77
 
77
78
  def hmerge(match)
@@ -20,10 +20,12 @@ module DefMastership
20
20
  (,\s*\[\s*(?<labels>.*?)\s*\])?\s*\]
21
21
  AFT
22
22
 
23
- DEF_CHECKSUM = '(\((?<explicit_checksum>[[:alnum:]]+)\))?'
23
+ DEF_VERSION_AND_CHECKSUM = '(?<version_and_checksum>' \
24
+ '\((?<explicit_version>[^~]+)?(?<explicit_checksum>~[[:alnum:]]+)?\)' \
25
+ ')?'
24
26
 
25
27
  DEFINITION = Regexp.new(
26
- "#{DEF_BEFORE_REF}(?<reference>[\\w:_-]+)#{DEF_CHECKSUM}#{DEF_AFTER_REF}",
28
+ "#{DEF_BEFORE_REF}(?<reference>[\\w:_-]+)#{DEF_VERSION_AND_CHECKSUM}#{DEF_AFTER_REF}",
27
29
  Regexp::EXTENDED
28
30
  )
29
31
 
@@ -8,18 +8,13 @@ require('defmastership/csv_formatter_body')
8
8
  module DefMastership
9
9
  # to export a CSV file
10
10
  class CSVFormatter
11
- COLUMN_LIST1 = %i[fixed wrong_explicit_checksum labels eref iref attributes].freeze
12
- COLUMN_LIST2 = %i[fixed labels eref iref attributes].freeze
13
- private_constant :COLUMN_LIST1
14
- private_constant :COLUMN_LIST2
15
-
16
11
  def initialize(doc, sep = ',')
17
12
  @doc = doc
18
13
  @sep = sep
19
14
  end
20
15
 
21
16
  def export_to(output_file)
22
- column_list = @doc.wrong_explicit_checksum? ? COLUMN_LIST1 : COLUMN_LIST2
17
+ column_list = build_column_list
23
18
  CSV.open(output_file, 'w:ISO-8859-1', { col_sep: @sep }) do |csv|
24
19
  csv << header(column_list)
25
20
  @doc.definitions.each { |definition| csv << body(definition, column_list) }
@@ -39,5 +34,16 @@ module DefMastership
39
34
  body_line = column_list.map { |part| body_formatter.public_send(part, definition) }
40
35
  body_line.reduce(:+)
41
36
  end
37
+
38
+ def build_column_list
39
+ column_list = [:fixed]
40
+ column_list += [:wrong_explicit_checksum] if @doc.wrong_explicit_checksum?
41
+ column_list += [:explicit_version] if @doc.explicit_version?
42
+ column_list += [:labels] unless @doc.labels.empty?
43
+ column_list += [:eref] unless @doc.eref.empty?
44
+ column_list += [:iref] if @doc.iref
45
+ column_list += [:attributes] unless @doc.attributes.empty?
46
+ column_list
47
+ end
42
48
  end
43
49
  end
@@ -19,8 +19,13 @@ module DefMastership
19
19
  wrong_explicit_checksum ? [wrong_explicit_checksum] : ['']
20
20
  end
21
21
 
22
+ def explicit_version(definition)
23
+ explicit_version = definition.explicit_version
24
+ explicit_version ? [explicit_version] : ['']
25
+ end
26
+
22
27
  def labels(definition)
23
- @doc.labels.empty? ? [] : [definition.labels.to_a.join("\n")]
28
+ [definition.labels.to_a.join("\n")]
24
29
  end
25
30
 
26
31
  def eref(definition)
@@ -28,13 +33,11 @@ module DefMastership
28
33
  end
29
34
 
30
35
  def iref(definition)
31
- @doc.iref ? [definition.iref.join("\n")] : []
36
+ [definition.iref.join("\n")]
32
37
  end
33
38
 
34
39
  def attributes(definition)
35
- @doc.attributes.map do |key, _|
36
- definition.attributes[key]
37
- end
40
+ @doc.attributes.map { |key, _| definition.attributes[key] }
38
41
  end
39
42
  end
40
43
  end
@@ -11,13 +11,17 @@ module DefMastership
11
11
  end
12
12
 
13
13
  def fixed
14
- %w[Type Reference Value sha256]
14
+ %w[Type Reference Value Checksum]
15
15
  end
16
16
 
17
17
  def wrong_explicit_checksum
18
18
  @doc.wrong_explicit_checksum? ? ['Wrong explicit checksum'] : []
19
19
  end
20
20
 
21
+ def explicit_version
22
+ @doc.explicit_version? ? ['Version'] : []
23
+ end
24
+
21
25
  def labels
22
26
  @doc.labels.empty? ? [] : %w[Labels]
23
27
  end
@@ -6,19 +6,19 @@ require 'digest'
6
6
  module DefMastership
7
7
  # DefMastership definition: contains all data of a definition
8
8
  class Definition
9
- attr_reader :type, :reference, :lines, :labels, :eref, :iref, :attributes
9
+ attr_reader :type, :reference, :lines, :labels, :eref, :iref, :attributes, :explicit_version
10
10
 
11
11
  def initialize(match)
12
12
  @type = match[:type]
13
13
  @reference = match[:reference]
14
14
  @lines = []
15
15
  @labels = Set.new
16
- labels = match[:labels]
17
- @labels.merge(labels.split(/\s*,\s*/).to_set) if labels
16
+ @labels.merge(match[:labels].split(/\s*,\s*/).to_set) if match[:labels]
18
17
  @eref = Hash.new([])
19
18
  @iref = []
20
19
  @attributes = {}
21
20
  @explicit_checksum = match[:explicit_checksum]
21
+ @explicit_version = match[:explicit_version]
22
22
  end
23
23
 
24
24
  def <<(new_line)
@@ -31,7 +31,7 @@ module DefMastership
31
31
  end
32
32
 
33
33
  def sha256
34
- Digest::SHA2.new(256).hexdigest(value).split(//).last(8).join
34
+ "~#{Digest::SHA2.new(256).hexdigest(value).chars.last(8).join}"
35
35
  end
36
36
 
37
37
  def wrong_explicit_checksum
@@ -18,7 +18,6 @@ module DefMastership
18
18
  @attributes = {}
19
19
  @in_literal = true
20
20
  @variables = {}
21
-
22
21
  @definition_parser = DefinitionParser.new(self)
23
22
  end
24
23
 
@@ -44,6 +43,12 @@ module DefMastership
44
43
  end
45
44
  end
46
45
 
46
+ def explicit_version?
47
+ @definitions.reduce(false) do |res, definition|
48
+ res || !definition.explicit_version.nil?
49
+ end
50
+ end
51
+
47
52
  def code_block_delimiter(_match, line)
48
53
  @in_literal ^= true
49
54
  line
@@ -67,17 +72,12 @@ module DefMastership
67
72
 
68
73
  def new_eref_setup(match, line)
69
74
  @eref[match[:refname].to_sym] ||= {}
70
-
71
- @eref[match[:refname].to_sym][match[:symb].to_sym] =
72
- match[:value]
75
+ @eref[match[:refname].to_sym][match[:symb].to_sym] = match[:value]
73
76
  line
74
77
  end
75
78
 
76
79
  def new_eref_def(match, line)
77
- @definitions.last.add_eref(
78
- match[:refname].to_sym,
79
- match[:extrefs]
80
- )
80
+ @definitions.last.add_eref(match[:refname].to_sym, match[:extrefs])
81
81
  line
82
82
  end
83
83
 
@@ -95,10 +95,7 @@ module DefMastership
95
95
  end
96
96
 
97
97
  def new_attribute_value(match, line)
98
- @definitions.last.set_attribute(
99
- match[:attr].to_sym,
100
- match[:value]
101
- )
98
+ @definitions.last.set_attribute(match[:attr].to_sym, match[:value])
102
99
  line
103
100
  end
104
101
 
@@ -108,14 +105,13 @@ module DefMastership
108
105
  end
109
106
 
110
107
  def new_variable_use(_match, line)
111
- new_line = line.dup
112
108
  line.scan(DMRegexp::VARIABLE_USE) do |_|
113
109
  varname = Regexp.last_match[:varname]
114
110
  next if @variables[varname.to_sym].nil?
115
111
 
116
- new_line.gsub!("{#{varname}}", @variables[varname.to_sym])
112
+ line = line.gsub("{#{varname}}", @variables[varname.to_sym])
117
113
  end
118
- new_line
114
+ line
119
115
  end
120
116
 
121
117
  private
@@ -96,7 +96,7 @@ module DefMastership
96
96
 
97
97
  filename.gsub!("{#{varname}}", @variables[varname.to_sym])
98
98
  end
99
- filename
99
+ filename.chomp
100
100
  end
101
101
 
102
102
  def complete_regexp_from(from)
@@ -23,9 +23,8 @@ module DefMastership
23
23
  return line unless match
24
24
  return line unless match[:type] == def_type
25
25
 
26
- explicit_checksum_str = match[:explicit_checksum].nil? ? '' : "(#{match[:explicit_checksum]})"
27
- line.gsub("#{match[:reference]}#{explicit_checksum_str}") do
28
- "#{match[:reference]}(#{@document.ref_to_def(match[:reference]).sha256})"
26
+ line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
27
+ "#{match[:reference]}(#{match[:explicit_version]}#{@document.ref_to_def(match[:reference]).sha256})"
29
28
  end
30
29
  end
31
30
 
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- # Update definition checksum wih calculated one
5
+ # Update definition checksum with calculated one
6
6
  class UpdateDefChecksumModifier < ModifierBase
7
7
  def replacements
8
8
  %i[replace]