defmastership 1.0.3 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +0 -1
  4. data/.rubocop.yml +3 -2
  5. data/Gemfile +1 -0
  6. data/LICENSE +22 -0
  7. data/Rakefile +2 -2
  8. data/bin/defmastership +37 -24
  9. data/cucumber.yml +2 -0
  10. data/defmastership.gemspec +16 -9
  11. data/features/changeref.feature +82 -129
  12. data/features/definition_checksum.feature +244 -0
  13. data/features/definition_version.feature +24 -0
  14. data/features/export.feature +49 -31
  15. data/features/modify.feature +165 -0
  16. data/features/rename_included_files.feature +121 -0
  17. data/features/step_definitions/defmastership_steps.rb +1 -0
  18. data/features/support/env.rb +1 -0
  19. data/lib/defmastership.rb +15 -3
  20. data/lib/defmastership/batch_modifier.rb +35 -0
  21. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +19 -35
  22. data/lib/defmastership/change_ref_modifier.rb +15 -0
  23. data/lib/defmastership/comment_filter.rb +1 -0
  24. data/lib/defmastership/constants.rb +15 -1
  25. data/lib/defmastership/csv_formatter.rb +26 -19
  26. data/lib/defmastership/csv_formatter_body.rb +20 -11
  27. data/lib/defmastership/csv_formatter_header.rb +16 -10
  28. data/lib/defmastership/definition.rb +15 -3
  29. data/lib/defmastership/definition_parser.rb +46 -0
  30. data/lib/defmastership/document.rb +60 -85
  31. data/lib/defmastership/filters.rb +30 -0
  32. data/lib/defmastership/line_modifier_base.rb +29 -0
  33. data/lib/defmastership/modifier_base.rb +29 -0
  34. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  35. data/lib/defmastership/rename_included_files_modifier.rb +15 -0
  36. data/lib/defmastership/update_def_checksum_line_modifier.rb +39 -0
  37. data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
  38. data/lib/defmastership/version.rb +2 -1
  39. data/spec/spec_helper.rb +2 -0
  40. data/spec/unit/defmastership/batch_modifier_spec.rb +123 -0
  41. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +49 -26
  42. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  43. data/spec/unit/defmastership/comment_filter_spec.rb +9 -4
  44. data/spec/unit/defmastership/csv_formatter_body_spec.rb +89 -82
  45. data/spec/unit/defmastership/csv_formatter_header_spec.rb +69 -22
  46. data/spec/unit/defmastership/csv_formatter_spec.rb +209 -110
  47. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  48. data/spec/unit/defmastership/definition_spec.rb +46 -4
  49. data/spec/unit/defmastership/document_spec.rb +237 -35
  50. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  51. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  52. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +68 -0
  53. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
  54. data/spec/unit/defmastership_spec.rb +1 -0
  55. metadata +49 -17
  56. data/Gemfile.lock +0 -140
  57. data/lib/defmastership/batch_changer.rb +0 -40
  58. data/lib/defmastership/project_ref_changer.rb +0 -27
  59. data/spec/unit/defmastership/batch_changer_spec.rb +0 -108
  60. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -79
@@ -0,0 +1,165 @@
1
+ Feature: The modify command
2
+ As a Responsible of definitions for a given document
3
+ In order to manage to applu predefined modifications
4
+ I want defmastership to apply automatic modifications
5
+
6
+ Scenario: Changes with one modifier
7
+ Given a file named "modifications.yml" with:
8
+ """
9
+ ---
10
+ :temp-references:
11
+ :type: change_ref
12
+ :config:
13
+ :from_regexp: TOTO-TEMP-[X\d]{4}
14
+ :to_template: TOTO-%<next_ref>04d
15
+ :next_ref: 123
16
+ """
17
+ And a file named "thedoc.adoc" with:
18
+ """
19
+ [define, requirement, TOTO-TEMP-XXX1]
20
+ """
21
+ When I successfully run `defmastership modify --modifications temp-references thedoc.adoc`
22
+ Then the stdout should not contain anything
23
+ And the stderr should not contain anything
24
+ And the file "modifications.yml" should contain:
25
+ """
26
+ ---
27
+ :temp-references:
28
+ :type: change_ref
29
+ :config:
30
+ :from_regexp: TOTO-TEMP-[X\d]{4}
31
+ :to_template: TOTO-%<next_ref>04d
32
+ :next_ref: 124
33
+ """
34
+ And the file "thedoc.adoc" should contain:
35
+ """
36
+ [define, requirement, TOTO-0123]
37
+ """
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
+
61
+ Scenario: Make modifications with yaml file parameter
62
+ Given a file named "pouet.yml" with:
63
+ """
64
+ ---
65
+ :toto:
66
+ :type: change_ref
67
+ :config:
68
+ :from_regexp: TOTO-TEMP-[X\d]{4}
69
+ :to_template: TOTO-%<next_ref>04d
70
+ :next_ref: 123
71
+ """
72
+ And a file named "thedoc.adoc" with:
73
+ """
74
+ [define, requirement, TOTO-TEMP-XXX1]
75
+ """
76
+ When I successfully run `defmastership modify --modifications-file=pouet.yml --modifications toto thedoc.adoc`
77
+ Then the stdout should not contain anything
78
+ And the stderr should not contain anything
79
+ And the file "pouet.yml" should contain:
80
+ """
81
+ ---
82
+ :toto:
83
+ :type: change_ref
84
+ :config:
85
+ :from_regexp: TOTO-TEMP-[X\d]{4}
86
+ :to_template: TOTO-%<next_ref>04d
87
+ :next_ref: 124
88
+ """
89
+ And the file "thedoc.adoc" should contain:
90
+ """
91
+ [define, requirement, TOTO-0123]
92
+ """
93
+
94
+ Scenario: Generate a table with changes
95
+ Given a file named "modifications.yml" with:
96
+ """
97
+ ---
98
+ :temp-references:
99
+ :type: change_ref
100
+ :config:
101
+ :from_regexp: TOTO-TEMP-[X\d]{4}
102
+ :to_template: TOTO-%<next_ref>04d
103
+ :next_ref: 123
104
+ """
105
+ And a file named "thedoc.adoc" with:
106
+ """
107
+ [define, requirement, TOTO-TEMP-XXX1]
108
+ [define, requirement, TOTO-TEMP-XXX2]
109
+ """
110
+ When I successfully run `defmastership modify --modifications temp-references --changes-summary=changes.csv thedoc.adoc`
111
+ Then the stderr should not contain anything
112
+ And the stdout should not contain anything
113
+ And the file "changes.csv" should contain:
114
+ """
115
+ Modifier,Was,Becomes
116
+ temp-references,TOTO-TEMP-XXX1,TOTO-0123
117
+ temp-references,TOTO-TEMP-XXX2,TOTO-0124
118
+ """
119
+
120
+ Scenario: Apply two modifcations
121
+ Given a file named "modifications.yml" with:
122
+ """
123
+ ---
124
+ :temp-references:
125
+ :type: change_ref
126
+ :config:
127
+ :from_regexp: TOTO-TEMP-[X\d]{4}
128
+ :to_template: TOTO-%<next_ref>04d
129
+ :next_ref: 123
130
+ :tata_or_titi:
131
+ :type: change_ref
132
+ :config:
133
+ :from_regexp: "(?<tata_or_titi>TATA|TITI)-TEMP-[X\\d]{4}"
134
+ :to_template: "%<tata_or_titi>s-%<next_ref>07d"
135
+ :next_ref: 432
136
+ """
137
+ And a file named "thedoc.adoc" with:
138
+ """
139
+ [define, requirement, TOTO-TEMP-XXX1]
140
+ [define, requirement, TITI-TEMP-XXX2]
141
+ """
142
+ When I successfully run `defmastership modify --modifications temp-references,tata_or_titi --changes-summary=changes.csv thedoc.adoc`
143
+ Then the stdout should not contain anything
144
+ And the stderr should not contain anything
145
+ And the file "modifications.yml" should contain:
146
+ """
147
+ ---
148
+ :temp-references:
149
+ :type: change_ref
150
+ :config:
151
+ :from_regexp: TOTO-TEMP-[X\d]{4}
152
+ :to_template: TOTO-%<next_ref>04d
153
+ :next_ref: 124
154
+ :tata_or_titi:
155
+ :type: change_ref
156
+ :config:
157
+ :from_regexp: "(?<tata_or_titi>TATA|TITI)-TEMP-[X\\d]{4}"
158
+ :to_template: "%<tata_or_titi>s-%<next_ref>07d"
159
+ :next_ref: 433
160
+ """
161
+ And the file "thedoc.adoc" should contain:
162
+ """
163
+ [define, requirement, TOTO-0123]
164
+ [define, requirement, TITI-0000432]
165
+ """
@@ -0,0 +1,121 @@
1
+
2
+ Feature: The rename_included_files command
3
+ As a Responsible of definitions for a given document.
4
+ In order to easy traceability with included files,
5
+ I want defmastership to change filename of included files to reflect
6
+ reference.
7
+
8
+ Scenario: do NOT change the filename of a file NOT included in a definition
9
+ Given a file named "modifications.yml" with:
10
+ """
11
+ ---
12
+ :rename_included_png:
13
+ :type: rename_included_files
14
+ :config:
15
+ :from_regexp: (?<origin>.*\.png)
16
+ :to_template: "%<reference>s_%<origin>s"
17
+ """
18
+ And a file named "thedoc.adoc" with:
19
+ """
20
+ include::any_path/one_file.png[]
21
+ """
22
+ And a directory named "any_path"
23
+ And an empty file named "any_path/one_file.png"
24
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
25
+ Then the stdout should not contain anything
26
+ And the stderr should not contain anything
27
+ And the file "thedoc.adoc" should contain:
28
+ """
29
+ include::any_path/one_file.png[]
30
+ """
31
+ And the file "any_path/one_file.png" should exist
32
+
33
+ Scenario: change the filename of a file included in a definition
34
+ Given a file named "modifications.yml" with:
35
+ """
36
+ ---
37
+ :rename_included_png:
38
+ :type: rename_included_files
39
+ :config:
40
+ :from_regexp: (?<origin>.*\.png)
41
+ :to_template: "%<reference>s_%<origin>s"
42
+ """
43
+ And a file named "thedoc.adoc" with:
44
+ """
45
+ [define, requirement, TOTO-WHATEVER-123]
46
+ include::any_path/one_file.png[]
47
+ """
48
+ And a directory named "any_path"
49
+ And an empty file named "any_path/one_file.png"
50
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
51
+ Then the stdout should not contain anything
52
+ And the stderr should not contain anything
53
+ And the file "thedoc.adoc" should contain:
54
+ """
55
+ [define, requirement, TOTO-WHATEVER-123]
56
+ include::any_path/TOTO-WHATEVER-123_one_file.png[]
57
+ """
58
+ And the file "any_path/one_file.png" should not exist
59
+ And the file "any_path/TOTO-WHATEVER-123_one_file.png" should exist
60
+
61
+ Scenario: change the filename with variable in path
62
+ Given a file named "modifications.yml" with:
63
+ """
64
+ ---
65
+ :rename_included_png:
66
+ :type: rename_included_files
67
+ :config:
68
+ :from_regexp: (?<origin>.*\.png)
69
+ :to_template: "%<reference>s_%<origin>s"
70
+ """
71
+ And a file named "thedoc.adoc" with:
72
+ """
73
+ :any: one
74
+ :path: two
75
+ [define, requirement, TOTO-WHATEVER-123]
76
+ include::{any}_{path}/one_file.png[]
77
+ """
78
+ And a directory named "one_two"
79
+ And an empty file named "one_two/one_file.png"
80
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
81
+ Then the stdout should not contain anything
82
+ And the stderr should not contain anything
83
+ And the file "thedoc.adoc" should contain:
84
+ """
85
+ :any: one
86
+ :path: two
87
+ [define, requirement, TOTO-WHATEVER-123]
88
+ include::{any}_{path}/TOTO-WHATEVER-123_one_file.png[]
89
+ """
90
+ And the file "one_two/one_file.png" should not exist
91
+ And the file "one_two/TOTO-WHATEVER-123_one_file.png" should exist
92
+
93
+ Scenario: DO NOT change the filename again and again
94
+ Given a file named "modifications.yml" with:
95
+ """
96
+ ---
97
+ :rename_included_png:
98
+ :type: rename_included_files
99
+ :config:
100
+ :from_regexp: (?<origin>.*\.png)
101
+ :cancel_if_match: TOTO-WHATEVER
102
+ :to_template: "%<reference>s_%<origin>s"
103
+ """
104
+ And a file named "thedoc.adoc" with:
105
+ """
106
+ [define, requirement, TOTO-WHATEVER-123]
107
+ include::any_path/TOTO-WHATEVER-123_one_file.png[]
108
+ """
109
+ And a directory named "any_path"
110
+ And an empty file named "any_path/TOTO-WHATEVER-123_one_file.png"
111
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
112
+ Then the stdout should not contain anything
113
+ And the stderr should not contain anything
114
+ And the file "thedoc.adoc" should contain:
115
+ """
116
+ [define, requirement, TOTO-WHATEVER-123]
117
+ include::any_path/TOTO-WHATEVER-123_one_file.png[]
118
+ """
119
+ And the file "any_path/one_file.png" should not exist
120
+ And the file "any_path/TOTO-WHATEVER-123_one_file.png" should exist
121
+
@@ -1,3 +1,4 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  When(/^I get help for "([^"]*)"$/) do |app_name|
@@ -1,3 +1,4 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('aruba/cucumber')
data/lib/defmastership.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership/version')
@@ -6,10 +7,21 @@ require('defmastership/version')
6
7
  # you just need to require this one file in your bin file
7
8
  require('defmastership/constants')
8
9
  require('defmastership/definition')
10
+ require('defmastership/definition_parser')
11
+ require('defmastership/filters')
9
12
  require('defmastership/document')
10
13
  require('defmastership/comment_filter')
11
14
  require('defmastership/csv_formatter')
12
15
 
13
- require('defmastership/ref_changer')
14
- require('defmastership/batch_changer')
15
- require('defmastership/project_ref_changer')
16
+ require('defmastership/modifier_base')
17
+ require('defmastership/line_modifier_base')
18
+ require('defmastership/batch_modifier')
19
+
20
+ require('defmastership/change_ref_modifier')
21
+ require('defmastership/change_ref_line_modifier')
22
+
23
+ require('defmastership/rename_included_files_modifier')
24
+ require('defmastership/rename_included_files_line_modifier')
25
+
26
+ require('defmastership/update_def_checksum_modifier')
27
+ require('defmastership/update_def_checksum_line_modifier')
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Change references from temporary to definitive with multiple RefChangers
6
+ class BatchModifier
7
+ attr_reader :config, :adoc_texts, :changes
8
+
9
+ def initialize(config, adoc_texts)
10
+ @config = config
11
+ @adoc_texts = adoc_texts
12
+ @changes = []
13
+ end
14
+
15
+ def apply(modifs)
16
+ modifs.split(/\s*,\s*/).each do |modif|
17
+ modifier = modifier_from(modif)
18
+ @adoc_texts = modifier.do_modifications(@adoc_texts)
19
+ @config[modif.to_sym][:config] = modifier.config
20
+ modifier.changes.each do |change|
21
+ @changes << [modif] + change
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def modifier_from(modif)
29
+ raise(ArgumentError, "#{modif} is not a known modification") if @config[modif.to_sym].nil?
30
+
31
+ class_name = "#{@config[modif.to_sym][:type].split('_').map(&:capitalize).join}Modifier"
32
+ DefMastership.const_get(class_name).new(@config[modif.to_sym][:config])
33
+ end
34
+ end
35
+ end
@@ -1,12 +1,11 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module DefMastership
4
- # Change references from temporary to definitive
5
- class RefChanger
6
- attr_reader :changes
7
-
8
- def self.from_h(hash)
9
- new.from_h(hash)
5
+ # Change references from temporary to definitive with multiple RefChangers
6
+ class ChangeRefLineModifier < LineModifierBase
7
+ def self.from_config(hash)
8
+ new.from_config(hash)
10
9
  end
11
10
 
12
11
  REGEXP_FROM = {
@@ -23,32 +22,17 @@ module DefMastership
23
22
  private_constant :REGEXP_FROM
24
23
 
25
24
  def initialize
26
- @h = {
25
+ super
26
+ @config = {
27
27
  from_regexp: '',
28
28
  to_template: '',
29
29
  next_ref: 0
30
30
  }
31
- @changes = []
32
31
  @in_literal = false
33
32
  end
34
33
 
35
- def method_missing(method_name, *args, &block)
36
- return @h[method_name] if @h[method_name]
37
-
38
- super
39
- end
40
-
41
- def respond_to_missing?(method_name, *args)
42
- @h[method_name] || super
43
- end
44
-
45
- def from_h(hash)
46
- @h.merge!(hash)
47
- self
48
- end
49
-
50
- def to_h
51
- @h
34
+ def replace(method, line)
35
+ public_send("replace_#{method}".to_sym, line)
52
36
  end
53
37
 
54
38
  def replace_refdef(line)
@@ -69,6 +53,15 @@ module DefMastership
69
53
 
70
54
  private
71
55
 
56
+ def do_replace_refdef(line)
57
+ line.gsub(regexp_from(:definition, from_regexp)) do
58
+ replacement = to_template % hmerge(Regexp.last_match)
59
+ changes << [Regexp.last_match[:from], replacement]
60
+ @config[:next_ref] += 1
61
+ text_with(Regexp.last_match, replacement)
62
+ end
63
+ end
64
+
72
65
  def regexp_from(const, from)
73
66
  regexp_str =
74
67
  "(?<before>#{REGEXP_FROM[const][:before]})" \
@@ -82,21 +75,12 @@ module DefMastership
82
75
  end
83
76
 
84
77
  def hmerge(match)
85
- @h.merge(Hash[match.names.map(&:to_sym).zip(match.captures)])
78
+ @config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
86
79
  end
87
80
 
88
81
  def in_literal(line)
89
82
  @in_literal ^= true if line.chomp == '....'
90
83
  @in_literal
91
84
  end
92
-
93
- def do_replace_refdef(line)
94
- line.gsub(regexp_from(:definition, from_regexp)) do
95
- replacement = to_template % hmerge(Regexp.last_match)
96
- changes << [Regexp.last_match[:from], replacement]
97
- @h[:next_ref] += 1
98
- text_with(Regexp.last_match, replacement)
99
- end
100
- end
101
85
  end
102
86
  end