defmastership 1.0.19 → 1.1.0

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 +3 -0
  3. data/.gitlab-ci.yml +27 -0
  4. data/Gemfile +27 -16
  5. data/LICENSE +1 -1
  6. data/README.adoc +24 -0
  7. data/Rakefile +0 -1
  8. data/bin/defmastership +5 -5
  9. data/config/mutant.yml +18 -16
  10. data/config/rubocop.yml +5 -10
  11. data/defmastership.gemspec +3 -3
  12. data/lib/defmastership/batch_modifier.rb +23 -5
  13. data/lib/defmastership/comment_filter.rb +2 -1
  14. data/lib/defmastership/definition.rb +24 -4
  15. data/lib/defmastership/definition_parser.rb +2 -2
  16. data/lib/defmastership/document.rb +39 -19
  17. data/lib/defmastership/export/body_formatter.rb +55 -0
  18. data/lib/defmastership/export/csv/formatter.rb +64 -0
  19. data/lib/defmastership/export/header_formatter.rb +51 -0
  20. data/lib/defmastership/filters.rb +15 -12
  21. data/lib/defmastership/matching_line.rb +3 -2
  22. data/lib/defmastership/modifier/change_ref.rb +117 -0
  23. data/lib/defmastership/modifier/factory.rb +17 -0
  24. data/lib/defmastership/modifier/modifier_common.rb +71 -0
  25. data/lib/defmastership/modifier/rename_included_files.rb +223 -0
  26. data/lib/defmastership/modifier/update_def.rb +72 -0
  27. data/lib/defmastership/modifier/update_def_checksum.rb +17 -0
  28. data/lib/defmastership/modifier/update_def_version.rb +110 -0
  29. data/lib/defmastership/set_join_hack.rb +2 -0
  30. data/lib/defmastership/version.rb +3 -2
  31. data/lib/defmastership.rb +6 -8
  32. data/spec/unit/{def_mastership → defmastership}/batch_modifier_spec.rb +13 -13
  33. data/spec/unit/{def_mastership → defmastership}/definition_parser_spec.rb +1 -1
  34. data/spec/unit/{def_mastership → defmastership}/definition_spec.rb +1 -1
  35. data/spec/unit/{def_mastership → defmastership}/document_spec.rb +57 -57
  36. data/spec/unit/{def_mastership/csv_formatter_body_spec.rb → defmastership/export/body_formatter_spec.rb} +4 -4
  37. data/spec/unit/{def_mastership/csv_formatter_spec.rb → defmastership/export/csv/formatter_spec.rb} +13 -8
  38. data/spec/unit/{def_mastership/csv_formatter_header_spec.rb → defmastership/export/header_formatter_spec.rb} +3 -3
  39. data/spec/unit/{def_mastership → defmastership}/matching_line_spec.rb +1 -1
  40. data/spec/unit/{def_mastership/change_ref_modifier_spec.rb → defmastership/modifier/change_ref_spec.rb} +19 -44
  41. data/spec/unit/defmastership/modifier/factory_spec.rb +45 -0
  42. data/spec/unit/{def_mastership/modifier_spec.rb → defmastership/modifier/modifier_common_spec.rb} +3 -12
  43. data/spec/unit/{def_mastership/rename_included_files_modifier_spec.rb → defmastership/modifier/rename_included_files_spec.rb} +3 -3
  44. data/spec/unit/{def_mastership/update_def_checksum_modifier_spec.rb → defmastership/modifier/update_def_checksum_spec.rb} +10 -10
  45. data/spec/unit/{def_mastership/update_def_modifier_spec.rb → defmastership/modifier/update_def_spec.rb} +22 -20
  46. data/spec/unit/{def_mastership/update_def_version_modifier_spec.rb → defmastership/modifier/update_def_version_spec.rb} +38 -38
  47. data/spec/unit/{def_mastership_spec.rb → defmastership_spec.rb} +2 -2
  48. data/tasks/documentation.rake +19 -0
  49. data/tasks/package.rake +4 -0
  50. metadata +63 -43
  51. data/README.rdoc +0 -6
  52. data/defmastership.rdoc +0 -5
  53. data/lib/defmastership/change_ref_modifier.rb +0 -99
  54. data/lib/defmastership/constants.rb +0 -91
  55. data/lib/defmastership/csv_formatter.rb +0 -53
  56. data/lib/defmastership/csv_formatter_body.rb +0 -46
  57. data/lib/defmastership/csv_formatter_header.rb +0 -41
  58. data/lib/defmastership/modifier.rb +0 -42
  59. data/lib/defmastership/modifier_factory.rb +0 -12
  60. data/lib/defmastership/parsing_state.rb +0 -31
  61. data/lib/defmastership/rename_included_files_modifier.rb +0 -182
  62. data/lib/defmastership/update_def_checksum_modifier.rb +0 -16
  63. data/lib/defmastership/update_def_modifier.rb +0 -49
  64. data/lib/defmastership/update_def_version_modifier.rb +0 -91
  65. data/spec/unit/def_mastership/modifier_factory_spec.rb +0 -38
  66. data/spec/unit/def_mastership/parsing_state_spec.rb +0 -62
  67. data/tasks/package.task +0 -9
  68. /data/spec/unit/{def_mastership → defmastership}/string_spec.rb +0 -0
@@ -1,91 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require 'defmastership/constants'
5
- require 'defmastership/update_def_modifier'
6
- require 'git'
7
- require 'tmpdir'
8
-
9
- module DefMastership
10
- # modify one line after another
11
- class UpdateDefVersionModifier < UpdateDefModifier
12
- def self.default_config
13
- {
14
- def_type: '',
15
- ref_document: [],
16
- ref_tag: '',
17
- ref_repo: '.',
18
- first_version: ''
19
- }
20
- end
21
-
22
- def initialize(config)
23
- @ref_document = Document.new
24
-
25
- Helper.normalilize_config(config) if config.key?(:ref_document)
26
-
27
- super
28
- end
29
-
30
- def do_modifications(adoc_sources)
31
- if ref_tag == ''
32
- ref_document.each { |ref_doc| @ref_document.parse_file_with_preprocessor(ref_doc) }
33
- else
34
- Dir.mktmpdir('defmastership') do |tmpdir|
35
- parse_ref_files_from_git(adoc_sources, tmpdir)
36
- end
37
- end
38
-
39
- super
40
- end
41
-
42
- private
43
-
44
- def parse_ref_files_from_git(adoc_sources, tmpdir)
45
- Git.clone(ref_repo, tmpdir, branch: ref_tag)
46
- ref_sources = ref_document.empty? ? adoc_sources.keys : ref_document
47
- ref_sources.each do |adoc_file|
48
- @ref_document.parse_file_with_preprocessor("#{tmpdir}/#{adoc_file}")
49
- end
50
- end
51
-
52
- def reference_replacement(reference, match)
53
- "#{reference}#{version_and_checksum_str(match)}"
54
- end
55
-
56
- def version_and_checksum_str(match)
57
- explicit_checksum = match[:explicit_checksum]
58
- version = version_string(match)
59
- return unless explicit_checksum || version
60
-
61
- "(#{version}#{explicit_checksum})"
62
- end
63
-
64
- def version_string(match)
65
- ref_definition = Helper.def_from_match(@ref_document, match)
66
- definition = Helper.def_from_match(document, match)
67
- return unless ref_definition
68
-
69
- Helper.ref_version(ref_definition, definition, first_version)
70
- end
71
-
72
- # Helper functions
73
- module Helper
74
- def self.def_from_match(doc, match)
75
- doc.ref_to_def(match[:reference])
76
- end
77
-
78
- def self.ref_version(ref_definition, definition, first_version)
79
- new_ref_version = ref_definition.explicit_version
80
- return new_ref_version if definition.sha256_short == ref_definition.sha256_short
81
-
82
- new_ref_version ? new_ref_version.next : first_version
83
- end
84
-
85
- def self.normalilize_config(config)
86
- ref_docs = config.fetch(:ref_document)
87
- config[:ref_document] = [ref_docs] if ref_docs.instance_of?(String)
88
- end
89
- end
90
- end
91
- end
@@ -1,38 +0,0 @@
1
- # Copyright (c) 2023 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('defmastership/modifier_factory')
5
-
6
- module DefMastership
7
- # Modifier example
8
- class TotoModifier
9
- include Modifier
10
- end
11
- end
12
-
13
- RSpec.describe(DefMastership::ModifierFactory) do
14
- describe('.from_config') do
15
- let(:toto) { instance_double(DefMastership::TotoModifier, 'toto') }
16
- let(:toto_config) { { type: 'toto', config: { p: 'whatever' } } }
17
- let(:tutu) { instance_double(DefMastership::TotoModifier, 'tutu') }
18
- let(:tutu_config) { { type: 'tu_tu', config: { p: 'whatever' } } }
19
-
20
- before do
21
- allow(DefMastership::TotoModifier).to(receive(:new).with(toto_config[:config]).and_return(toto))
22
- allow(DefMastership::TuTuModifier).to(receive(:new).with(tutu_config[:config]).and_return(tutu))
23
- end
24
-
25
- it { expect(described_class.from_config(toto_config)).to(be(toto)) }
26
- it { expect(described_class.from_config(tutu_config)).to(be(tutu)) }
27
-
28
- it do
29
- described_class.from_config(toto_config)
30
- expect(DefMastership::TotoModifier).to(have_received(:new).with(toto_config[:config]))
31
- end
32
-
33
- it do
34
- described_class.from_config(tutu_config)
35
- expect(DefMastership::TuTuModifier).to(have_received(:new).with(tutu_config[:config]))
36
- end
37
- end
38
- end
@@ -1,62 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('defmastership/parsing_state')
5
-
6
- RSpec.describe(DefMastership::ParsingState) do
7
- subject(:parsing_state) do
8
- described_class.new
9
- end
10
-
11
- describe '.new' do
12
- it { is_expected.not_to(be_nil) }
13
- end
14
-
15
- describe '#enabled_with?' do
16
- context 'when single line commment' do
17
- it { expect(parsing_state.enabled?("//whatever\n")).to(be(false)) }
18
- end
19
-
20
- context 'when starting' do
21
- it { expect(parsing_state.enabled?("whatever\n")).to(be(true)) }
22
- it { expect(parsing_state.enabled?("----\n")).to(be(false)) }
23
- it { expect(parsing_state.enabled?("....\n")).to(be(false)) }
24
- it { expect(parsing_state.enabled?("////\n")).to(be(false)) }
25
- it { expect(parsing_state.enabled?('....')).to(be(false)) }
26
- end
27
-
28
- context 'when disabled' do
29
- before { parsing_state.enabled?("----\n") }
30
-
31
- it { expect(parsing_state.enabled?("whatever\n")).to(be(false)) }
32
- it { expect(parsing_state.enabled?("----\n")).to(be(true)) }
33
- it { expect(parsing_state.enabled?("....\n")).to(be(false)) }
34
- it { expect(parsing_state.enabled?("////\n")).to(be(false)) }
35
- end
36
-
37
- context 'with intricated disables starting with "...."' do
38
- before do
39
- ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
40
- end
41
-
42
- it { expect(parsing_state.enabled?("----\n")).to(be(false)) }
43
- it { expect(parsing_state.enabled?("....\n")).to(be(true)) }
44
- end
45
-
46
- context 'with intricated disables starting with "----"' do
47
- before do
48
- ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
49
- end
50
-
51
- it { expect(parsing_state.enabled?("....\n")).to(be(true)) }
52
- end
53
-
54
- context 'with intricated disables starting with "////"' do
55
- before do
56
- ["////\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
57
- end
58
-
59
- it { expect(parsing_state.enabled?("////\n")).to(be(true)) }
60
- end
61
- end
62
- end
data/tasks/package.task DELETED
@@ -1,9 +0,0 @@
1
- # Copyright (c) 2023 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('rubygems')
5
- require('rubygems/package_task')
6
-
7
- spec = eval(File.read('defmastership.gemspec'))
8
-
9
- Gem::PackageTask.new(spec)