defmastership 1.0.16 → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +50 -7
  4. data/.rubocop.yml +14 -6
  5. data/Gemfile +51 -1
  6. data/Rakefile +16 -47
  7. data/bin/defmastership +12 -9
  8. data/config/mutant.yml +23 -3
  9. data/defmastership.gemspec +22 -27
  10. data/features/definition_checksum.feature +31 -1
  11. data/features/export.feature +43 -1
  12. data/features/rename_included_files.feature +28 -0
  13. data/lib/defmastership/batch_modifier.rb +17 -12
  14. data/lib/defmastership/change_ref_modifier.rb +89 -5
  15. data/lib/defmastership/comment_filter.rb +1 -1
  16. data/lib/defmastership/constants.rb +5 -4
  17. data/lib/defmastership/csv_formatter.rb +20 -16
  18. data/lib/defmastership/csv_formatter_body.rb +18 -15
  19. data/lib/defmastership/csv_formatter_header.rb +1 -1
  20. data/lib/defmastership/definition.rb +58 -19
  21. data/lib/defmastership/document.rb +109 -74
  22. data/lib/defmastership/matching_line.rb +17 -0
  23. data/lib/defmastership/modifier.rb +42 -0
  24. data/lib/defmastership/modifier_factory.rb +12 -0
  25. data/lib/defmastership/parsing_state.rb +15 -9
  26. data/lib/defmastership/rename_included_files_modifier.rb +172 -5
  27. data/lib/defmastership/set_join_hack.rb +11 -0
  28. data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
  29. data/lib/defmastership/update_def_modifier.rb +49 -0
  30. data/lib/defmastership/update_def_version_modifier.rb +56 -15
  31. data/lib/defmastership/version.rb +1 -1
  32. data/lib/defmastership.rb +7 -17
  33. data/spec/spec_helper.rb +4 -2
  34. data/spec/unit/{defmastership → def_mastership}/batch_modifier_spec.rb +42 -39
  35. data/spec/unit/{defmastership/change_ref_line_modifier_spec.rb → def_mastership/change_ref_modifier_spec.rb} +44 -66
  36. data/spec/unit/{defmastership → def_mastership}/csv_formatter_body_spec.rb +61 -32
  37. data/spec/unit/{defmastership → def_mastership}/csv_formatter_header_spec.rb +2 -2
  38. data/spec/unit/{defmastership → def_mastership}/csv_formatter_spec.rb +81 -86
  39. data/spec/unit/{defmastership → def_mastership}/definition_parser_spec.rb +2 -2
  40. data/spec/unit/{defmastership → def_mastership}/definition_spec.rb +17 -7
  41. data/spec/unit/{defmastership → def_mastership}/document_spec.rb +108 -53
  42. data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
  43. data/spec/unit/def_mastership/modifier_factory_spec.rb +37 -0
  44. data/spec/unit/def_mastership/modifier_spec.rb +83 -0
  45. data/spec/unit/{defmastership → def_mastership}/parsing_state_spec.rb +16 -16
  46. data/spec/unit/{defmastership/rename_included_files_line_modifier_spec.rb → def_mastership/rename_included_files_modifier_spec.rb} +72 -36
  47. data/spec/unit/{defmastership/comment_filter_spec.rb → def_mastership/string_spec.rb} +1 -1
  48. data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +107 -0
  49. data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
  50. data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +159 -0
  51. data/spec/unit/{defmastership_spec.rb → def_mastership_spec.rb} +1 -1
  52. data/tasks/console.rake +8 -0
  53. data/tasks/package.task +9 -0
  54. data/tasks/smelling_code.rake +38 -0
  55. data/tasks/test.rake +45 -0
  56. metadata +37 -145
  57. data/lib/defmastership/change_ref_line_modifier.rb +0 -82
  58. data/lib/defmastership/line_modifier_base.rb +0 -29
  59. data/lib/defmastership/modifier_base.rb +0 -29
  60. data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
  61. data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
  62. data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
  63. data/spec/unit/defmastership/change_ref_modifier_spec.rb +0 -76
  64. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +0 -67
  65. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +0 -78
  66. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +0 -75
  67. data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +0 -127
  68. data/spec/unit/defmastership/update_def_version_modifier_spec.rb +0 -80
data/tasks/test.rake ADDED
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('cucumber/rake/task')
5
+ require('rspec/core/rake_task')
6
+
7
+ namespace 'test' do
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ cuke_results = 'features_results.html'
11
+ CLEAN << cuke_results
12
+
13
+ Cucumber::Rake::Task.new(:features) do |t|
14
+ opts = ['features'] +
15
+ ['--format', 'html'] +
16
+ ['-o', cuke_results] +
17
+ ['--format', 'progress'] +
18
+ ['-x']
19
+
20
+ opts += ['--tags', ENV.fetch('TAGS').split.join(' or ')] if ENV['TAGS']
21
+ t.cucumber_opts = opts
22
+ end
23
+
24
+ Cucumber::Rake::Task.new('features:wip') do |t|
25
+ t.cucumber_opts = ['features'] +
26
+ ['--format', 'html'] +
27
+ ['-o', cuke_results] +
28
+ ['--format', 'pretty'] +
29
+ ['-x'] +
30
+ ['-s'] +
31
+ ['--tags', '@wip and not @pending']
32
+ end
33
+
34
+ desc 'Runs all unit tests and acceptance tests'
35
+ task(all: ['test:spec', 'test:features'])
36
+ end
37
+
38
+ desc 'Synonym for test:spec'
39
+ task(spec: 'test:spec')
40
+
41
+ desc 'Synonym for test:all'
42
+ task(test: 'test:all')
43
+
44
+ desc('Test all features')
45
+ task(cucumber: 'test:features')
metadata CHANGED
@@ -1,127 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defmastership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérôme Arbez-Gindre
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2024-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: aruba
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '13'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '13'
41
- - !ruby/object:Gem::Dependency
42
- name: rdoc
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '6'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '6'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '='
74
- - !ruby/object:Gem::Version
75
- version: '1.13'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '='
81
- - !ruby/object:Gem::Version
82
- version: '1.13'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.5'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.5'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '2.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '2.0'
111
- - !ruby/object:Gem::Dependency
112
- name: simplecov
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
13
  - !ruby/object:Gem::Dependency
126
14
  name: aasm
127
15
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +52,7 @@ dependencies:
164
52
  - - "~>"
165
53
  - !ruby/object:Gem::Version
166
54
  version: '2'
167
- description:
55
+ description:
168
56
  email: jeromearbezgindre@gmail.com
169
57
  executables:
170
58
  - defmastership
@@ -203,7 +91,6 @@ files:
203
91
  - features/support/env.rb
204
92
  - lib/defmastership.rb
205
93
  - lib/defmastership/batch_modifier.rb
206
- - lib/defmastership/change_ref_line_modifier.rb
207
94
  - lib/defmastership/change_ref_modifier.rb
208
95
  - lib/defmastership/comment_filter.rb
209
96
  - lib/defmastership/constants.rb
@@ -214,40 +101,45 @@ files:
214
101
  - lib/defmastership/definition_parser.rb
215
102
  - lib/defmastership/document.rb
216
103
  - lib/defmastership/filters.rb
217
- - lib/defmastership/line_modifier_base.rb
218
- - lib/defmastership/modifier_base.rb
104
+ - lib/defmastership/matching_line.rb
105
+ - lib/defmastership/modifier.rb
106
+ - lib/defmastership/modifier_factory.rb
219
107
  - lib/defmastership/parsing_state.rb
220
- - lib/defmastership/rename_included_files_line_modifier.rb
221
108
  - lib/defmastership/rename_included_files_modifier.rb
222
- - lib/defmastership/update_def_checksum_line_modifier.rb
109
+ - lib/defmastership/set_join_hack.rb
223
110
  - lib/defmastership/update_def_checksum_modifier.rb
224
- - lib/defmastership/update_def_version_line_modifier.rb
111
+ - lib/defmastership/update_def_modifier.rb
225
112
  - lib/defmastership/update_def_version_modifier.rb
226
113
  - lib/defmastership/version.rb
227
114
  - spec/spec_helper.rb
228
- - spec/unit/defmastership/batch_modifier_spec.rb
229
- - spec/unit/defmastership/change_ref_line_modifier_spec.rb
230
- - spec/unit/defmastership/change_ref_modifier_spec.rb
231
- - spec/unit/defmastership/comment_filter_spec.rb
232
- - spec/unit/defmastership/csv_formatter_body_spec.rb
233
- - spec/unit/defmastership/csv_formatter_header_spec.rb
234
- - spec/unit/defmastership/csv_formatter_spec.rb
235
- - spec/unit/defmastership/definition_parser_spec.rb
236
- - spec/unit/defmastership/definition_spec.rb
237
- - spec/unit/defmastership/document_spec.rb
238
- - spec/unit/defmastership/parsing_state_spec.rb
239
- - spec/unit/defmastership/rename_included_files_line_modifier_spec.rb
240
- - spec/unit/defmastership/rename_included_files_modifier_spec.rb
241
- - spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb
242
- - spec/unit/defmastership/update_def_checksum_modifier_spec.rb
243
- - spec/unit/defmastership/update_def_version_line_modifier_spec.rb
244
- - spec/unit/defmastership/update_def_version_modifier_spec.rb
245
- - spec/unit/defmastership_spec.rb
115
+ - spec/unit/def_mastership/batch_modifier_spec.rb
116
+ - spec/unit/def_mastership/change_ref_modifier_spec.rb
117
+ - spec/unit/def_mastership/csv_formatter_body_spec.rb
118
+ - spec/unit/def_mastership/csv_formatter_header_spec.rb
119
+ - spec/unit/def_mastership/csv_formatter_spec.rb
120
+ - spec/unit/def_mastership/definition_parser_spec.rb
121
+ - spec/unit/def_mastership/definition_spec.rb
122
+ - spec/unit/def_mastership/document_spec.rb
123
+ - spec/unit/def_mastership/matching_line_spec.rb
124
+ - spec/unit/def_mastership/modifier_factory_spec.rb
125
+ - spec/unit/def_mastership/modifier_spec.rb
126
+ - spec/unit/def_mastership/parsing_state_spec.rb
127
+ - spec/unit/def_mastership/rename_included_files_modifier_spec.rb
128
+ - spec/unit/def_mastership/string_spec.rb
129
+ - spec/unit/def_mastership/update_def_checksum_modifier_spec.rb
130
+ - spec/unit/def_mastership/update_def_modifier_spec.rb
131
+ - spec/unit/def_mastership/update_def_version_modifier_spec.rb
132
+ - spec/unit/def_mastership_spec.rb
133
+ - tasks/console.rake
134
+ - tasks/package.task
135
+ - tasks/smelling_code.rake
136
+ - tasks/test.rake
246
137
  homepage: https://gitlab.com/jjag/defmastership/
247
138
  licenses:
248
139
  - MIT
249
- metadata: {}
250
- post_install_message:
140
+ metadata:
141
+ rubygems_mfa_required: 'true'
142
+ post_install_message:
251
143
  rdoc_options:
252
144
  - "--title defmastership"
253
145
  - "--main README.rdoc"
@@ -259,15 +151,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
259
151
  requirements:
260
152
  - - ">="
261
153
  - !ruby/object:Gem::Version
262
- version: '2.5'
154
+ version: '2.7'
263
155
  required_rubygems_version: !ruby/object:Gem::Requirement
264
156
  requirements:
265
157
  - - ">="
266
158
  - !ruby/object:Gem::Version
267
159
  version: '0'
268
160
  requirements: []
269
- rubygems_version: 3.2.5
270
- signing_key:
161
+ rubygems_version: 3.5.6
162
+ signing_key:
271
163
  specification_version: 4
272
164
  summary: Handling of references and definitions with asciidoctor
273
165
  test_files: []
@@ -1,82 +0,0 @@
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 ChangeRefLineModifier < LineModifierBase
7
- def self.from_config(hash)
8
- new.from_config(hash)
9
- end
10
-
11
- REGEXP_FROM = {
12
- definition: {
13
- before: DMRegexp::DEF_BEFORE_REF,
14
- after: DMRegexp::DEF_AFTER_REF
15
- },
16
- iref: {
17
- before: DMRegexp::IREF_DEF_BEF,
18
- after: DMRegexp::IREF_DEF_AFT
19
- }
20
- }.freeze
21
-
22
- private_constant :REGEXP_FROM
23
-
24
- def initialize
25
- super
26
- @config = {
27
- from_regexp: '',
28
- to_template: '',
29
- next_ref: 0
30
- }
31
- @parsing_state = ParsingState.new
32
- end
33
-
34
- def replace(method, line)
35
- public_send("replace_#{method}".to_sym, line)
36
- end
37
-
38
- def replace_refdef(line)
39
- if @parsing_state.enabled?(line)
40
- do_replace_refdef(line)
41
- else
42
- line
43
- end
44
- end
45
-
46
- def replace_irefs(line)
47
- changes.reduce(line) do |res_line, (from, to)|
48
- res_line.gsub(regexp_from(:iref, from)) do
49
- text_with(Regexp.last_match, to)
50
- end
51
- end
52
- end
53
-
54
- private
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
-
65
- def regexp_from(const, from)
66
- regexp_str =
67
- "(?<before>#{REGEXP_FROM[const][:before]})" \
68
- "(?<from>#{from})" \
69
- "#{DMRegexp::DEF_VERSION_AND_CHECKSUM}" \
70
- "(?<after>#{REGEXP_FROM[const][:after]})"
71
- Regexp.new(regexp_str, Regexp::EXTENDED)
72
- end
73
-
74
- def text_with(match, replacement)
75
- match[:before] + replacement + (match[:version_and_checksum] || '') + match[:after]
76
- end
77
-
78
- def hmerge(match)
79
- @config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
80
- end
81
- end
82
- end
@@ -1,29 +0,0 @@
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 LineModifierBase
7
- attr_reader :changes, :config
8
-
9
- def initialize
10
- @config = {}
11
- @changes = []
12
- end
13
-
14
- def method_missing(method_name, *args, &block)
15
- return @config[method_name] if @config[method_name]
16
-
17
- super
18
- end
19
-
20
- def respond_to_missing?(method_name, *args)
21
- @config[method_name] || super
22
- end
23
-
24
- def from_config(config)
25
- @config.merge!(config)
26
- self
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
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 ModifierBase
7
- attr_reader :config, :changes
8
-
9
- def initialize(config)
10
- @config = config
11
- @changes = []
12
- end
13
-
14
- def do_modifications(adoc_texts)
15
- line_modifier = new_line_modifier(@config, adoc_texts)
16
-
17
- adoc_texts =
18
- replacements.reduce(adoc_texts) do |texts, method|
19
- texts.transform_values do |text|
20
- text.lines.map { |line| line_modifier.public_send(method, line) }.join
21
- end
22
- end
23
-
24
- @config = line_modifier.config
25
- @changes = line_modifier.changes
26
- adoc_texts
27
- end
28
- end
29
- end
@@ -1,126 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- module DefMastership
5
- # Change included filenames on one line at a time
6
- class RenameIncludedFilesLineModifier < LineModifierBase
7
- LOCAL_FILTERS = [
8
- Filter.new(DMRegexp::VARIABLE_DEF, :new_variable_def, false),
9
- Filter.new(DMRegexp::DEFINITION, :new_definition, true),
10
- Filter.new(DMRegexp::BLOCK, :block_delimiter, true),
11
- Filter.new(DMRegexp::EMPTY_LINE, :empty_line, false),
12
- Filter.new(DMRegexp::WHATEVER, :new_line, true)
13
- ].freeze
14
- private_constant :LOCAL_FILTERS
15
-
16
- def self.from_config(config)
17
- new.from_config(config)
18
- end
19
-
20
- def initialize
21
- super
22
- @config = {
23
- from_regexp: '',
24
- to_template: ''
25
- }
26
- @variables = {}
27
- @definition_parser = DefinitionParser.new(self)
28
- end
29
-
30
- def replace(line)
31
- match = matched?(line)
32
-
33
- return line unless match
34
-
35
- new_line =
36
- line.gsub(complete_regexp_from(from_regexp)) do
37
- text_with(match, to_template % hmerge(match))
38
- end
39
-
40
- rename_file(line, new_line)
41
-
42
- new_line
43
- end
44
-
45
- def add_new_definition(match, _line)
46
- @config[:reference] = match[:reference]
47
- end
48
-
49
- def add_line(_match, _line) end
50
-
51
- def new_variable_def(match, line)
52
- @variables[match[:varname].to_sym] = match[:value]
53
- line
54
- end
55
-
56
- private
57
-
58
- def matched?(line)
59
- return if line.commented?
60
-
61
- parse(line)
62
-
63
- return if @definition_parser.idle?
64
- return unless line =~ complete_regexp_from(from_regexp)
65
-
66
- match = Regexp.last_match
67
-
68
- return if @config[:cancel_if_match] && match[:filename] =~ Regexp.new(cancel_if_match)
69
-
70
- match
71
- end
72
-
73
- def parse(line)
74
- LOCAL_FILTERS.each do |filter|
75
- next unless line.match(filter.regexp)
76
-
77
- line = generate_event(filter.event, Regexp.last_match, line)
78
-
79
- break if filter.consumed_line
80
- end
81
- end
82
-
83
- def rename_file(from, to)
84
- @changes << [extract_filename(from), extract_filename(to)]
85
- File.rename(extract_filename(from), extract_filename(to))
86
- end
87
-
88
- def extract_filename(include_statement)
89
- filename = include_statement
90
- .gsub(Regexp.new(DMRegexp::INCLUDE_KEYWORD), '')
91
- .gsub(Regexp.new(DMRegexp::INCLUDE_OPTIONS), '')
92
-
93
- filename.dup.scan(DMRegexp::VARIABLE_USE) do |_|
94
- varname = Regexp.last_match[:varname]
95
- next if @variables[varname.to_sym].nil?
96
-
97
- filename.gsub!("{#{varname}}", @variables[varname.to_sym])
98
- end
99
- filename.chomp
100
- end
101
-
102
- def complete_regexp_from(from)
103
- Regexp.new(
104
- DMRegexp::INCLUDE_KEYWORD + DMRegexp::INCLUDE_PATH +
105
- "(?<filename>#{from})" + DMRegexp::INCLUDE_OPTIONS
106
- )
107
- end
108
-
109
- def text_with(match, to)
110
- "include::#{match[:path] || ''}#{to}[#{match[:options]}]"
111
- end
112
-
113
- def hmerge(match)
114
- @config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
115
- end
116
-
117
- def generate_event(event, match, line)
118
- if respond_to?(event)
119
- public_send(event, match, line)
120
- else
121
- @definition_parser.public_send(event, match, line)
122
- end
123
- line
124
- end
125
- end
126
- end
@@ -1,38 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- module DefMastership
5
- # modify one line after another
6
- class UpdateDefChecksumLineModifier < LineModifierBase
7
- attr_accessor :document
8
-
9
- def self.from_config(hash)
10
- new.from_config(hash)
11
- end
12
-
13
- def initialize
14
- super
15
- @config = {
16
- def_type: ''
17
- }
18
- end
19
-
20
- def replace(line)
21
- match = matched?(line)
22
-
23
- return line unless match
24
- return line unless match[:type] == def_type
25
-
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})"
28
- end
29
- end
30
-
31
- def matched?(line)
32
- return if line.commented?
33
- return unless line =~ DMRegexp::DEFINITION
34
-
35
- Regexp.last_match
36
- end
37
- end
38
- end
@@ -1,58 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- module DefMastership
5
- # modify one line after another
6
- class UpdateDefVersionLineModifier < LineModifierBase
7
- attr_accessor :document, :ref_document
8
-
9
- def self.from_config(hash)
10
- new.from_config(hash)
11
- end
12
-
13
- def initialize
14
- super
15
- @config = {
16
- def_type: '',
17
- ref_document: '',
18
- first_version: ''
19
- }
20
- end
21
-
22
- def replace(line)
23
- match = matched?(line)
24
-
25
- return line unless match
26
- return line unless match[:type] == def_type
27
-
28
- version_and_checksum = ''
29
- if match[:explicit_checksum] || version_string(match)
30
- version_and_checksum = "(#{version_string(match)}#{match[:explicit_checksum]})"
31
- end
32
-
33
- line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
34
- "#{match[:reference]}#{version_and_checksum}"
35
- end
36
- end
37
-
38
- private
39
-
40
- def matched?(line)
41
- return if line.commented?
42
- return unless line =~ DMRegexp::DEFINITION
43
-
44
- Regexp.last_match
45
- end
46
-
47
- def version_string(match)
48
- ref_definition = @ref_document.ref_to_def(match[:reference])
49
- definition = @document.ref_to_def(match[:reference])
50
-
51
- return if ref_definition.nil?
52
- return ref_definition.explicit_version if definition.sha256 == ref_definition.sha256
53
-
54
- ref_version = @ref_document.ref_to_def(match[:reference]).explicit_version
55
- ref_version.nil? ? @config[:first_version] : ref_version.next
56
- end
57
- end
58
- end