defmastership 1.3.2 → 1.3.4

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -9
  3. data/Guardfile +2 -5
  4. data/Rakefile +1 -1
  5. data/config/mutant.yml +2 -1
  6. data/config/rubocop.yml +20 -8
  7. data/defmastership.gemspec +6 -15
  8. data/features/changeref.feature +108 -0
  9. data/features/definition_checksum.feature +118 -0
  10. data/features/definition_version.feature +168 -0
  11. data/features/export.feature +122 -22
  12. data/features/external_ref_checksum.feature +169 -0
  13. data/features/external_ref_version.feature +173 -0
  14. data/features/internal_ref_checksum.feature +77 -0
  15. data/features/internal_ref_version.feature +81 -0
  16. data/features/rename_included_files.feature +55 -0
  17. data/features/step_definitions/git_steps.rb +3 -0
  18. data/lib/defmastership/app.rb +35 -8
  19. data/lib/defmastership/comment_filter.rb +2 -0
  20. data/lib/defmastership/def_type_list.rb +25 -0
  21. data/lib/defmastership/definition_parser.rb +2 -6
  22. data/lib/defmastership/document.rb +6 -9
  23. data/lib/defmastership/export/csv/formatter.rb +8 -60
  24. data/lib/defmastership/export/formatter.rb +88 -0
  25. data/lib/defmastership/export/json/formatter.rb +34 -0
  26. data/lib/defmastership/export/xlsx/formatter.rb +87 -0
  27. data/lib/defmastership/export/yaml/formatter.rb +34 -0
  28. data/lib/defmastership/modifier/change_ref.rb +24 -39
  29. data/lib/defmastership/modifier/factory.rb +5 -1
  30. data/lib/defmastership/modifier/modifier_common.rb +4 -4
  31. data/lib/defmastership/modifier/rename_included_files.rb +16 -5
  32. data/lib/defmastership/modifier/replacement_formatter.rb +37 -0
  33. data/lib/defmastership/modifier/update_def.rb +7 -2
  34. data/lib/defmastership/modifier/update_eref_checksum.rb +46 -0
  35. data/lib/defmastership/modifier/update_eref_common.rb +78 -0
  36. data/lib/defmastership/modifier/update_eref_version.rb +46 -0
  37. data/lib/defmastership/modifier/update_iref_checksum.rb +52 -0
  38. data/lib/defmastership/modifier/update_iref_common.rb +45 -0
  39. data/lib/defmastership/modifier/update_iref_version.rb +59 -0
  40. data/lib/defmastership/version.rb +1 -1
  41. data/spec/spec_helper.rb +11 -10
  42. data/spec/unit/defmastership/app_spec.rb +57 -20
  43. data/spec/unit/defmastership/batch_modifier_spec.rb +9 -7
  44. data/spec/unit/defmastership/def_type_list_spec.rb +22 -0
  45. data/spec/unit/defmastership/definition_spec.rb +8 -51
  46. data/spec/unit/defmastership/document_spec.rb +12 -36
  47. data/spec/unit/defmastership/export/body_formatter_spec.rb +5 -18
  48. data/spec/unit/defmastership/export/csv/formatter_spec.rb +45 -231
  49. data/spec/unit/defmastership/export/formatter_spec.rb +97 -0
  50. data/spec/unit/defmastership/export/header_formatter_spec.rb +2 -6
  51. data/spec/unit/defmastership/export/json/formatter_spec.rb +85 -0
  52. data/spec/unit/defmastership/export/xlsx/formatter_spec.rb +82 -0
  53. data/spec/unit/defmastership/export/yaml/formatter_spec.rb +85 -0
  54. data/spec/unit/defmastership/hash_spec.rb +2 -0
  55. data/spec/unit/defmastership/modifier/change_ref_spec.rb +66 -97
  56. data/spec/unit/defmastership/modifier/factory_spec.rb +40 -17
  57. data/spec/unit/defmastership/modifier/modifier_common_spec.rb +7 -5
  58. data/spec/unit/defmastership/modifier/rename_included_files_spec.rb +105 -85
  59. data/spec/unit/defmastership/modifier/update_def_checksum_spec.rb +6 -13
  60. data/spec/unit/defmastership/modifier/update_def_spec.rb +79 -22
  61. data/spec/unit/defmastership/modifier/update_def_version_spec.rb +13 -37
  62. data/spec/unit/defmastership/modifier/update_eref_checksum_spec.rb +209 -0
  63. data/spec/unit/defmastership/modifier/update_eref_version_spec.rb +227 -0
  64. data/spec/unit/defmastership/modifier/update_iref_checksum_spec.rb +133 -0
  65. data/spec/unit/defmastership/modifier/update_iref_version_spec.rb +162 -0
  66. data/tasks/code_quality.rake +1 -8
  67. data/tasks/test.rake +15 -0
  68. metadata +59 -6
@@ -2,52 +2,26 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require('defmastership/core/constants')
5
+ require('defmastership/core/parsing_state')
6
+ require('defmastership/def_type_list')
5
7
  require('defmastership/modifier/modifier_common')
6
8
  require('facets/file/writelines')
7
9
 
8
10
  module Defmastership
9
11
  module Modifier
10
12
  # Change references from temporary to definitive with multiple RefChangers
13
+ # This class smells of :reek:DataClump
11
14
  class ChangeRef
12
15
  include ModifierCommon
13
16
 
14
- # [Regexp] match all text before the definition's reference
15
- DEF_BEFORE_REF = <<~"BEF".freeze
16
- ^
17
- \\s*
18
- \\[
19
- #{Core::DMRegexp::DEF_KEYWORD}
20
- #{Core::DMRegexp::DEF_TYPE}
21
- ,
22
- \\s*
23
- BEF
24
- private_constant :DEF_BEFORE_REF
25
-
26
- # [Regexp] match all text after the definition's reference
27
- DEF_AFTER_REF = <<~"AFT".freeze
28
- \\s*
29
- #{Core::DMRegexp::DEF_SUMMARY}
30
- #{Core::DMRegexp::DEF_LABELS}
31
- \\s*
32
- \\]
33
- AFT
34
- private_constant :DEF_AFTER_REF
35
-
36
- # [Regexp] match the begining of an internal cross reference
37
- IREF_DEF_BEF = 'defs:iref\[\s*'
38
- private_constant :IREF_DEF_BEF
39
- # [Regexp] match the end of an internal cross reference
40
- IREF_DEF_AFT = '\s*\]'
41
- private_constant :IREF_DEF_AFT
42
-
43
17
  REGEXP_FROM = {
44
18
  definition: {
45
- before: DEF_BEFORE_REF,
46
- after: DEF_AFTER_REF
19
+ before: Core::DMRegexp::DEF_BEFORE_REF,
20
+ after: Core::DMRegexp::DEF_AFTER_REF
47
21
  },
48
22
  iref: {
49
- before: IREF_DEF_BEF,
50
- after: IREF_DEF_AFT
23
+ before: Core::DMRegexp::IREF_DEF_BEF,
24
+ after: Core::DMRegexp::IREF_DEF_AFT
51
25
  }
52
26
  }.freeze
53
27
 
@@ -63,6 +37,7 @@ module Defmastership
63
37
  # @return [Hash{Symbol => Object}] the default configuration
64
38
  def self.default_config
65
39
  {
40
+ def_type: '',
66
41
  from_regexp: '',
67
42
  to_template: '',
68
43
  next_ref: 0
@@ -78,9 +53,11 @@ module Defmastership
78
53
 
79
54
  # Replace the definition's ref in the line if relevant
80
55
  #
56
+ # @param _filename [String] the filename of the file beeing modified
81
57
  # @param line [String] the current line
82
58
  # @return [String] the modified line
83
- def replace_refdef(line)
59
+ # This method smells of :reek:DataClump
60
+ def replace_refdef(_filename, line)
84
61
  if @parsing_state.enabled?(line)
85
62
  do_replace_refdef(line)
86
63
  else
@@ -90,9 +67,10 @@ module Defmastership
90
67
 
91
68
  # Replace the definition's refs in intenal refs
92
69
  #
70
+ # @param _filename [String] the filename of the file beeing modified
93
71
  # @param line [String] the current line
94
72
  # @return [String] the modified line
95
- def replace_irefs(line)
73
+ def replace_irefs(_filename, line)
96
74
  changes.reduce(line) do |res_line, (from, to)|
97
75
  res_line.gsub(Helper.regexp_from(:iref, from)) do
98
76
  Helper.text_with(Regexp.last_match, to)
@@ -102,9 +80,10 @@ module Defmastership
102
80
 
103
81
  # Replace the definition's refs in tags of include statements
104
82
  #
83
+ # @param _filename [String] the filename of the file beeing modified
105
84
  # @param line [String] the current line
106
85
  # @return [String] the modified line
107
- def replace_include_tags(line)
86
+ def replace_include_tags(_filename, line)
108
87
  return line unless line.match?(Core::DMRegexp::INCLUDE)
109
88
 
110
89
  changes.reduce(line) do |res_line, (from, to)|
@@ -114,11 +93,14 @@ module Defmastership
114
93
 
115
94
  # Replace the definition's refs in included files
116
95
  #
96
+ # @param filename [String] the filename of the file beeing modified
117
97
  # @param line [String] the current line
118
98
  # @return [String] the (unmodified) line
119
- def replace_tags_in_included_files(line)
99
+ def replace_tags_in_included_files(filename, line)
120
100
  if line.match(Core::DMRegexp::INCLUDE)
121
- Helper.replace_tags_in_included_files(Helper::ParsedFilename.full_filename(Regexp.last_match), changes)
101
+ Helper.replace_tags_in_included_files(
102
+ "#{Pathname(filename).dirname}/#{Helper::ParsedFilename.full_filename(Regexp.last_match)}", changes
103
+ )
122
104
  end
123
105
  line
124
106
  end
@@ -127,7 +109,10 @@ module Defmastership
127
109
 
128
110
  def do_replace_refdef(line)
129
111
  line.sub(Helper.regexp_from(:definition, from_regexp)) do
130
- replacement_from(Regexp.last_match)
112
+ last_match = Regexp.last_match
113
+ return line unless DefTypeList.new(config.fetch(:def_type)).include?(last_match[:type])
114
+
115
+ replacement_from(last_match)
131
116
  end
132
117
  end
133
118
 
@@ -5,6 +5,10 @@ require('defmastership/modifier/change_ref')
5
5
  require('defmastership/modifier/rename_included_files')
6
6
  require('defmastership/modifier/update_def_checksum')
7
7
  require('defmastership/modifier/update_def_version')
8
+ require('defmastership/modifier/update_eref_checksum')
9
+ require('defmastership/modifier/update_eref_version')
10
+ require('defmastership/modifier/update_iref_checksum')
11
+ require('defmastership/modifier/update_iref_version')
8
12
 
9
13
  module Defmastership
10
14
  module Modifier
@@ -15,7 +19,7 @@ module Defmastership
15
19
  # @param config [YAML] piece of configuration for this Modifier
16
20
  def self.from_config(config)
17
21
  class_name = config.fetch(:type).split('_').map(&:capitalize).join
18
- Modifier.const_get(class_name).new(config.fetch(:config))
22
+ Modifier.const_get(class_name).new(config.fetch(:config, {}))
19
23
  end
20
24
  end
21
25
  end
@@ -57,13 +57,13 @@ module Defmastership
57
57
  private
58
58
 
59
59
  def apply_to_all(texts, method)
60
- texts.transform_values do |text|
61
- apply_to_one(text, method)
60
+ texts.to_h do |filename, text|
61
+ [filename, apply_to_one(filename, text, method)]
62
62
  end
63
63
  end
64
64
 
65
- def apply_to_one(text, method)
66
- text.lines.map { |line| public_send(method, line) }
65
+ def apply_to_one(filename, text, method)
66
+ text.lines.map { |line| public_send(method, filename, line) }
67
67
  .join
68
68
  end
69
69
  end
@@ -1,7 +1,11 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
+ require('defmastership/def_type_list')
5
+ require('defmastership/definition_parser')
4
6
  require('defmastership/filters')
7
+ require('defmastership/matching_line')
8
+ require('defmastership/modifier/modifier_common')
5
9
 
6
10
  module Defmastership
7
11
  # defintion of the Rename Included Files Modifier
@@ -26,6 +30,7 @@ module Defmastership
26
30
  add_line: proc { |_| },
27
31
  add_new_definition: lambda { |matching_line|
28
32
  config[:reference] = matching_line.match[:reference]
33
+ @current_def_type = matching_line.match[:type]
29
34
  }
30
35
  }.freeze
31
36
 
@@ -39,15 +44,18 @@ module Defmastership
39
44
  # @return [Hash{Symbol => Object}] the default configuration
40
45
  def self.default_config
41
46
  {
47
+ def_type: '',
42
48
  from_regexp: '',
43
49
  to_template: ''
44
50
  }
45
51
  end
46
52
 
47
53
  # @param config [YAML] the modifier's provided configurations
54
+ # mutant:disable
48
55
  def initialize(config)
49
56
  @variables = {}
50
57
  @definition_parser = DefinitionParser.new(self)
58
+ @current_def_type = nil
51
59
 
52
60
  setup_modifier_module(config)
53
61
  end
@@ -73,15 +81,17 @@ module Defmastership
73
81
 
74
82
  # Modify line if it match
75
83
  #
84
+ # @param filename [String] the filename of the file beeing modified
85
+ # @param line [String] the current line
76
86
  # @return [String] the modified line
77
- def replace(line)
87
+ def replace(filename, line)
78
88
  match = matched?(line)
79
89
 
80
90
  return line unless match
81
91
 
82
92
  new_line = build_new_include_line(match, line)
83
93
 
84
- rename_file(line, new_line)
94
+ rename_file(Pathname(filename).dirname, line, new_line)
85
95
 
86
96
  new_line
87
97
  end
@@ -109,6 +119,7 @@ module Defmastership
109
119
  parse(line)
110
120
 
111
121
  return false if @definition_parser.idle?
122
+ return false unless DefTypeList.new(config.fetch(:def_type)).include?(@current_def_type)
112
123
 
113
124
  true
114
125
  end
@@ -119,9 +130,9 @@ module Defmastership
119
130
  end
120
131
  end
121
132
 
122
- def rename_file(from, to)
123
- filename_from = Helper.extract_filename(from, @variables)
124
- filename_to = Helper.extract_filename(to, @variables)
133
+ def rename_file(dirname, from, to)
134
+ filename_from = "#{dirname}/#{Helper.extract_filename(from, @variables)}"
135
+ filename_to = "#{dirname}/#{Helper.extract_filename(to, @variables)}"
125
136
  changes << [filename_from, filename_to]
126
137
  File.rename(filename_from, filename_to)
127
138
  end
@@ -0,0 +1,37 @@
1
+ # lib/defmastership/modifier/replacement_formatter.rb
2
+
3
+ # Copyright (c) 2025 Jerome Arbez-Gindre
4
+ # frozen_string_literal: true
5
+
6
+ require 'memoist'
7
+
8
+ module Defmastership
9
+ module Modifier
10
+ # A small, single-purpose class to format a ref replacement string.
11
+ class ReplacementFormatter
12
+ extend Memoist
13
+
14
+ # @param match_data [MatchData] of the ref statement
15
+ # @param document [Document] the overall parsed document
16
+ # @param key [Symbol] the key to access the reference in match_data
17
+ def initialize(match_data, document, key)
18
+ @match_data = match_data
19
+ @document = document
20
+ @key = key
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :match_data, :document, :key
26
+
27
+ def reference_string
28
+ match_data[key]
29
+ end
30
+
31
+ def definition
32
+ document.ref_to_def(reference_string)
33
+ end
34
+ memoize :definition
35
+ end
36
+ end
37
+ end
@@ -1,6 +1,10 @@
1
1
  # Copyright (c) 2024 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'defmastership/def_type_list'
5
+ require 'defmastership/document'
6
+ require 'defmastership/modifier/modifier_common'
7
+
4
8
  module Defmastership
5
9
  module Modifier
6
10
  # @abstract Subclass and define +reference_replacement+ to implement a
@@ -54,13 +58,14 @@ module Defmastership
54
58
 
55
59
  # Called on each line for an opportunity for text replacement
56
60
  #
61
+ # @param _filename [String] the filename of the file beeing modified
57
62
  # @param line [String] line from asciidoc sources files
58
63
  # @return [String] the modified line
59
- def replace_reference(line)
64
+ def replace_reference(_filename, line)
60
65
  match = line.match(Core::DMRegexp::DEFINITION)
61
66
 
62
67
  return line unless match
63
- return line unless match[:type].eql?(def_type)
68
+ return line unless DefTypeList.new(def_type).include?(match[:type])
64
69
 
65
70
  reference = match[:reference]
66
71
  line.sub(self.class.reference_regexp(reference), reference_replacement(reference, match))
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2025 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require 'defmastership/modifier/update_eref_common'
5
+
6
+ module Defmastership
7
+ module Modifier
8
+ # Update external refs checksum
9
+ class UpdateErefChecksum < UpdateEref
10
+ # Methods's symbols will be called in sequence to perform the document modifications
11
+ #
12
+ # @return [Array<Symbol>] the two symbols of replacement methods
13
+ def self.replacement_methods
14
+ %i[replace_erefs]
15
+ end
16
+
17
+ private
18
+
19
+ # Provides the specific formatter class for checksum replacements.
20
+ def formatter_class
21
+ Helper::ErefReplacementFormatterChecksum
22
+ end
23
+
24
+ # Helper functions/classes
25
+ module Helper
26
+ # A small, single-purpose class to format the eref replacement string.
27
+ class ErefReplacementFormatterChecksum < ReplacementFormatter
28
+ # @param match_data [MatchData] of the ref statement
29
+ # @param document [Document] the overall parsed document
30
+ def initialize(match_data, document)
31
+ super(match_data, document, :reference)
32
+ end
33
+
34
+ # @return [String] the formatted string or the original match if no definition is found.
35
+ def to_s
36
+ version = match_data[:explicit_version]
37
+ checksum = definition ? definition.sha256_short : match_data[:explicit_checksum]
38
+ return reference_string unless version || checksum
39
+
40
+ "#{reference_string}(#{version}#{checksum})"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,78 @@
1
+ # Copyright (c) 2025 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require 'defmastership/def_type_list'
5
+ require 'defmastership/modifier/modifier_common'
6
+ require 'defmastership/modifier/replacement_formatter'
7
+
8
+ module Defmastership
9
+ module Modifier
10
+ # Update external refs version
11
+ class UpdateEref
12
+ include ModifierCommon
13
+
14
+ # @return [Hash{Symbol => Object}] the default configuration
15
+ def self.default_config
16
+ {
17
+ eref_type: '',
18
+ ref_document: ''
19
+ }
20
+ end
21
+
22
+ # @param config [YAML] the modifier's provided configurations
23
+ def initialize(config)
24
+ @the_ref_document = Document.new
25
+
26
+ setup_modifier_module(config)
27
+ end
28
+
29
+ # Apply the modifier on all provided asciidoc sources based on modifier's
30
+ # +self.replacement_methods+ list
31
+ #
32
+ # @param adoc_sources [Hash{String => String}] asciidoc sources
33
+ # * :key filename
34
+ # * :value file content
35
+ def do_modifications(adoc_sources)
36
+ Array(ref_document).each { |ref_doc| the_ref_document.parse_file_with_preprocessor(ref_doc) }
37
+
38
+ super
39
+ end
40
+
41
+ # Replace the definition's external ref in the line if relevant
42
+ #
43
+ # @param _filename [String] the filename of the file beeing modified
44
+ # @param line [String] the current line
45
+ # @return [String] the modified line
46
+ def replace_erefs(_filename, line)
47
+ match = line.match(Core::DMRegexp::EREF_DEF)
48
+ # Return early if there's no match or the type is not valid
49
+ return line unless match && eref_type_valid?(match[:reference])
50
+
51
+ # Delegate the actual replacement to a separate method
52
+ perform_replacement(line, match[:extrefs])
53
+ end
54
+
55
+ private
56
+
57
+ # Performs the nested gsub replacement
58
+ #
59
+ # @param line [String] the current line
60
+ # @param extrefs [String] all teh matched external references
61
+ # @return [String] the modified line
62
+ def perform_replacement(line, extrefs)
63
+ line.sub(extrefs) do
64
+ extrefs.gsub(Regexp.new(Core::DMRegexp::REF_WITH_OPT_VER_CHK)) do
65
+ formatter_class.new(Regexp.last_match, the_ref_document)
66
+ end
67
+ end
68
+ end
69
+
70
+ attr_reader :the_ref_document
71
+
72
+ # Checks if the given eref type should be processed
73
+ def eref_type_valid?(this_eref_type)
74
+ DefTypeList.new(eref_type).include?(this_eref_type)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2025 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require 'defmastership/modifier/update_eref_common'
5
+
6
+ module Defmastership
7
+ module Modifier
8
+ # Update external refs version
9
+ class UpdateErefVersion < UpdateEref
10
+ # Methods's symbols will be called in sequence to perform the document modifications
11
+ #
12
+ # @return [Array<Symbol>] the two symbols of replacement methods
13
+ def self.replacement_methods
14
+ %i[replace_erefs]
15
+ end
16
+
17
+ private
18
+
19
+ # Provides the specific formatter class for checksum replacements.
20
+ def formatter_class
21
+ Helper::ErefReplacementFormatterVersion
22
+ end
23
+
24
+ # Helper functions/classes
25
+ module Helper
26
+ # A small, single-purpose class to format the eref replacement string.
27
+ class ErefReplacementFormatterVersion < ReplacementFormatter
28
+ # @param match_data [MatchData] of the ref statement
29
+ # @param document [Document] the overall parsed document
30
+ def initialize(match_data, document)
31
+ super(match_data, document, :reference)
32
+ end
33
+
34
+ # @return [String] the formatted string or the original match if no definition is found.
35
+ def to_s
36
+ version = definition ? definition.explicit_version : match_data[:explicit_version]
37
+ checksum = match_data[:explicit_checksum]
38
+ return reference_string unless version || checksum
39
+
40
+ "#{reference_string}(#{version}#{checksum})"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2025 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/core/constants')
5
+ require('defmastership/modifier/replacement_formatter')
6
+ require('defmastership/modifier/update_iref_common')
7
+
8
+ module Defmastership
9
+ module Modifier
10
+ # Update internal refs checksum
11
+ class UpdateIrefChecksum < UpdateIref
12
+ include ModifierCommon
13
+
14
+ # Methods's symbols will be called in sequence to perform the document modifications
15
+ #
16
+ # @return [Array<Symbol>] the two symbols of replacement methods
17
+ def self.replacement_methods
18
+ %i[replace_irefs]
19
+ end
20
+
21
+ # Replace the definition's internal ref in the line if relevant
22
+ #
23
+ # @param _filename [String] the filename of the file beeing modified
24
+ # @param line [String] the current line
25
+ # @return [String] the modified line
26
+ def replace_irefs(_filename, line)
27
+ line.gsub(Core::DMRegexp::IREF_DEF) do
28
+ Helper::IrefReplacementFormatterChecksum.new(Regexp.last_match, document).to_s
29
+ end
30
+ end
31
+
32
+ # Helper functions/classes
33
+ module Helper
34
+ # A small, single-purpose class to format the iref replacement string.
35
+ class IrefReplacementFormatterChecksum < ReplacementFormatter
36
+ # @param match_data [MatchData] of the ref statement
37
+ # @param document [Document] the overall parsed document
38
+ def initialize(match_data, document)
39
+ super(match_data, document, :intref)
40
+ end
41
+
42
+ # @return [String] the formatted string or the original match if no definition is found.
43
+ def to_s
44
+ return match_data unless definition
45
+
46
+ "defs:iref[#{reference_string}(#{match_data[:explicit_version]}#{definition.sha256_short})]"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2025 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/core/constants')
5
+ require('defmastership/document')
6
+ require('defmastership/modifier/modifier_common')
7
+
8
+ module Defmastership
9
+ module Modifier
10
+ # Update internal refs checksum
11
+ class UpdateIref
12
+ include ModifierCommon
13
+
14
+ # @return [Hash{Symbol => Object}] the default configuration
15
+ def self.default_config
16
+ {}
17
+ end
18
+
19
+ # @param config [YAML] the modifier's provided configurations
20
+ def initialize(config)
21
+ @document = Document.new
22
+
23
+ setup_modifier_module(config)
24
+ end
25
+
26
+ # Apply the modifier on all provided asciidoc sources based on modifier's
27
+ # +self.replacement_methods+ list
28
+ #
29
+ # @param adoc_sources [Hash{String => String}] asciidoc sources
30
+ # * :key filename
31
+ # * :value file content
32
+ def do_modifications(adoc_sources)
33
+ adoc_sources.each_key do |adoc_file|
34
+ document.parse_file_with_preprocessor(adoc_file)
35
+ end
36
+
37
+ super
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :document
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2025 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/core/constants')
5
+ require('defmastership/modifier/replacement_formatter')
6
+ require('defmastership/modifier/update_iref_common')
7
+
8
+ module Defmastership
9
+ module Modifier
10
+ # Update internal refs checksum
11
+ class UpdateIrefVersion < UpdateIref
12
+ include ModifierCommon
13
+
14
+ # Methods's symbols will be called in sequence to perform the document modifications
15
+ #
16
+ # @return [Array<Symbol>] the two symbols of replacement methods
17
+ def self.replacement_methods
18
+ %i[replace_irefs]
19
+ end
20
+
21
+ # Replace the definition's internal ref in the line if relevant
22
+ #
23
+ # @param _filename [String] the filename of the file beeing modified
24
+ # @param line [String] the current line
25
+ # @return [String] the modified line
26
+ def replace_irefs(_filename, line)
27
+ line.gsub(Core::DMRegexp::IREF_DEF) do
28
+ Helper::IrefReplacementFormatterVersion.new(Regexp.last_match, document).to_s
29
+ end
30
+ end
31
+
32
+ # Helper functions/classes
33
+ module Helper
34
+ # A small, single-purpose class to format the iref replacement string.
35
+ class IrefReplacementFormatterVersion < ReplacementFormatter
36
+ # @param match_data [MatchData] of the ref statement
37
+ # @param document [Document] the overall parsed document
38
+ def initialize(match_data, document)
39
+ super(match_data, document, :intref)
40
+ end
41
+
42
+ # @return [String] the formatted string or the original match if no definition is found.
43
+ def to_s
44
+ return match_data unless definition
45
+
46
+ explicit_version = definition.explicit_version
47
+ explicit_checksum = match_data[:explicit_checksum]
48
+
49
+ if explicit_version || explicit_checksum
50
+ "defs:iref[#{reference_string}(#{explicit_version}#{explicit_checksum})]"
51
+ else
52
+ "defs:iref[#{reference_string}]"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Defmastership
5
5
  # [String] Gem version
6
- VERSION = '1.3.2'
6
+ VERSION = '1.3.4'
7
7
  public_constant :VERSION
8
8
  end
data/spec/spec_helper.rb CHANGED
@@ -6,19 +6,20 @@ require('aasm/rspec')
6
6
  # formatter = [SimpleCov::Formatter::HTMLFormatter]
7
7
  # SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(formatter)
8
8
 
9
- require('simplecov')
9
+ unless ENV['CODE_COVERAGE_IN_RSPEC'] && ENV['DISABLE_CODE_COVERAGE_IN_RSPEC'] != 'disabled'
10
+ require 'simplecov'
11
+ SimpleCov.start do
12
+ command_name 'spec:unit'
10
13
 
11
- SimpleCov.start do
12
- command_name 'spec:unit'
14
+ add_group 'Libraries', 'lib'
15
+ add_group 'Unit test', 'spec/unit'
13
16
 
14
- add_group 'Libraries', 'lib'
15
- add_group 'Unit test', 'spec/unit'
17
+ add_filter 'config'
18
+ add_filter 'vendor'
16
19
 
17
- add_filter 'config'
18
- add_filter 'vendor'
19
-
20
- enable_coverage :branch
21
- minimum_coverage line: 100, branch: 100
20
+ enable_coverage :branch
21
+ minimum_coverage line: 100, branch: 100
22
+ end
22
23
  end
23
24
 
24
25
  RSpec::Matchers.define(:matchdata_including) do |h|