defmastership 1.0.19 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.gitlab-ci.yml +27 -0
- data/Gemfile +27 -16
- data/LICENSE +1 -1
- data/README.adoc +24 -0
- data/Rakefile +0 -1
- data/bin/defmastership +5 -5
- data/config/mutant.yml +18 -16
- data/config/rubocop.yml +5 -10
- data/defmastership.gemspec +3 -3
- data/lib/defmastership/batch_modifier.rb +23 -5
- data/lib/defmastership/comment_filter.rb +2 -1
- data/lib/defmastership/definition.rb +24 -4
- data/lib/defmastership/definition_parser.rb +2 -2
- data/lib/defmastership/document.rb +39 -19
- data/lib/defmastership/export/body_formatter.rb +55 -0
- data/lib/defmastership/export/csv/formatter.rb +64 -0
- data/lib/defmastership/export/header_formatter.rb +51 -0
- data/lib/defmastership/filters.rb +15 -12
- data/lib/defmastership/matching_line.rb +3 -2
- data/lib/defmastership/modifier/change_ref.rb +117 -0
- data/lib/defmastership/modifier/factory.rb +17 -0
- data/lib/defmastership/modifier/modifier_common.rb +71 -0
- data/lib/defmastership/modifier/rename_included_files.rb +223 -0
- data/lib/defmastership/modifier/update_def.rb +72 -0
- data/lib/defmastership/modifier/update_def_checksum.rb +17 -0
- data/lib/defmastership/modifier/update_def_version.rb +110 -0
- data/lib/defmastership/set_join_hack.rb +2 -0
- data/lib/defmastership/version.rb +3 -2
- data/lib/defmastership.rb +6 -8
- data/spec/unit/{def_mastership → defmastership}/batch_modifier_spec.rb +13 -13
- data/spec/unit/{def_mastership → defmastership}/definition_parser_spec.rb +1 -1
- data/spec/unit/{def_mastership → defmastership}/definition_spec.rb +1 -1
- data/spec/unit/{def_mastership → defmastership}/document_spec.rb +57 -57
- data/spec/unit/{def_mastership/csv_formatter_body_spec.rb → defmastership/export/body_formatter_spec.rb} +4 -4
- data/spec/unit/{def_mastership/csv_formatter_spec.rb → defmastership/export/csv/formatter_spec.rb} +13 -8
- data/spec/unit/{def_mastership/csv_formatter_header_spec.rb → defmastership/export/header_formatter_spec.rb} +3 -3
- data/spec/unit/{def_mastership → defmastership}/matching_line_spec.rb +1 -1
- data/spec/unit/{def_mastership/change_ref_modifier_spec.rb → defmastership/modifier/change_ref_spec.rb} +19 -44
- data/spec/unit/defmastership/modifier/factory_spec.rb +45 -0
- data/spec/unit/{def_mastership/modifier_spec.rb → defmastership/modifier/modifier_common_spec.rb} +3 -12
- data/spec/unit/{def_mastership/rename_included_files_modifier_spec.rb → defmastership/modifier/rename_included_files_spec.rb} +3 -3
- data/spec/unit/{def_mastership/update_def_checksum_modifier_spec.rb → defmastership/modifier/update_def_checksum_spec.rb} +10 -10
- data/spec/unit/{def_mastership/update_def_modifier_spec.rb → defmastership/modifier/update_def_spec.rb} +22 -20
- data/spec/unit/{def_mastership/update_def_version_modifier_spec.rb → defmastership/modifier/update_def_version_spec.rb} +38 -38
- data/spec/unit/{def_mastership_spec.rb → defmastership_spec.rb} +2 -2
- data/tasks/documentation.rake +19 -0
- data/tasks/package.rake +4 -0
- metadata +63 -43
- data/README.rdoc +0 -6
- data/defmastership.rdoc +0 -5
- data/lib/defmastership/change_ref_modifier.rb +0 -99
- data/lib/defmastership/constants.rb +0 -91
- data/lib/defmastership/csv_formatter.rb +0 -53
- data/lib/defmastership/csv_formatter_body.rb +0 -46
- data/lib/defmastership/csv_formatter_header.rb +0 -41
- data/lib/defmastership/modifier.rb +0 -42
- data/lib/defmastership/modifier_factory.rb +0 -12
- data/lib/defmastership/parsing_state.rb +0 -31
- data/lib/defmastership/rename_included_files_modifier.rb +0 -182
- data/lib/defmastership/update_def_checksum_modifier.rb +0 -16
- data/lib/defmastership/update_def_modifier.rb +0 -49
- data/lib/defmastership/update_def_version_modifier.rb +0 -91
- data/spec/unit/def_mastership/modifier_factory_spec.rb +0 -38
- data/spec/unit/def_mastership/parsing_state_spec.rb +0 -62
- data/tasks/package.task +0 -9
- /data/spec/unit/{def_mastership → defmastership}/string_spec.rb +0 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'defmastership/modifier/update_def'
|
5
|
+
require 'git'
|
6
|
+
require 'tmpdir'
|
7
|
+
|
8
|
+
module Defmastership
|
9
|
+
module Modifier
|
10
|
+
# modify one line after another
|
11
|
+
class UpdateDefVersion < UpdateDef
|
12
|
+
# @return [Hash{Symbol => Object}] the default configuration
|
13
|
+
def self.default_config
|
14
|
+
{
|
15
|
+
def_type: '',
|
16
|
+
ref_document: [],
|
17
|
+
ref_tag: '',
|
18
|
+
ref_repo: '.',
|
19
|
+
first_version: ''
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param config [YAML] the modifier's provided configurations
|
24
|
+
def initialize(config)
|
25
|
+
@ref_document = Document.new
|
26
|
+
|
27
|
+
Helper.normalilize_config!(config) if config.key?(:ref_document)
|
28
|
+
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
# Apply the modifier on all provided asciidoc sources based on modifier's
|
33
|
+
# +self.replacement_methods+ list
|
34
|
+
#
|
35
|
+
# @param adoc_sources [Hash{String => String}] asciidoc sources
|
36
|
+
# * :key filename
|
37
|
+
# * :value file content
|
38
|
+
def do_modifications(adoc_sources)
|
39
|
+
if ref_tag == ''
|
40
|
+
ref_document.each { |ref_doc| @ref_document.parse_file_with_preprocessor(ref_doc) }
|
41
|
+
else
|
42
|
+
Dir.mktmpdir('defmastership') do |tmpdir|
|
43
|
+
parse_ref_files_from_git(adoc_sources, tmpdir)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def parse_ref_files_from_git(adoc_sources, tmpdir)
|
53
|
+
Git.clone(ref_repo, tmpdir, branch: ref_tag)
|
54
|
+
ref_sources = ref_document.empty? ? adoc_sources.keys : ref_document
|
55
|
+
ref_sources.each do |adoc_file|
|
56
|
+
@ref_document.parse_file_with_preprocessor("#{tmpdir}/#{adoc_file}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def reference_replacement(reference, match)
|
61
|
+
"#{reference}#{version_and_checksum_str(match)}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def version_and_checksum_str(match)
|
65
|
+
explicit_checksum = match[:explicit_checksum]
|
66
|
+
version = version_string(match)
|
67
|
+
return unless explicit_checksum || version
|
68
|
+
|
69
|
+
"(#{version}#{explicit_checksum})"
|
70
|
+
end
|
71
|
+
|
72
|
+
def version_string(match)
|
73
|
+
ref_definition = Helper.def_from_match(@ref_document, match)
|
74
|
+
definition = Helper.def_from_match(document, match)
|
75
|
+
return unless ref_definition
|
76
|
+
|
77
|
+
Helper.ref_version(ref_definition, definition, first_version)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Helper functions
|
81
|
+
module Helper
|
82
|
+
# @param doc [Document] the document with defintions
|
83
|
+
# @param match [MatchData] Regexp match matching a reference
|
84
|
+
# @return [Definition] the definition from a +Document+ with a matching reference
|
85
|
+
def self.def_from_match(doc, match)
|
86
|
+
doc.ref_to_def(match[:reference])
|
87
|
+
end
|
88
|
+
|
89
|
+
# @param ref_definition [Definition] the definition from the reference document
|
90
|
+
# @param definition [Definition] the definition from the current document
|
91
|
+
# @param first_version [String] first version from configuration
|
92
|
+
# @return [String] the current definition version
|
93
|
+
def self.ref_version(ref_definition, definition, first_version)
|
94
|
+
new_ref_version = ref_definition.explicit_version
|
95
|
+
return new_ref_version if definition.sha256_short == ref_definition.sha256_short
|
96
|
+
|
97
|
+
new_ref_version ? new_ref_version.next : first_version
|
98
|
+
end
|
99
|
+
|
100
|
+
# Make sure that ref_document configuration is an Array
|
101
|
+
#
|
102
|
+
# @param config [YAML] the definition from the reference document
|
103
|
+
def self.normalilize_config!(config)
|
104
|
+
ref_docs = config.fetch(:ref_document)
|
105
|
+
config[:ref_document] = [ref_docs] if ref_docs.instance_of?(String)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/lib/defmastership.rb
CHANGED
@@ -6,16 +6,14 @@ require('defmastership/version')
|
|
6
6
|
# Add requires for other files you add to your project here, so
|
7
7
|
# you just need to require this one file in your bin file
|
8
8
|
require('defmastership/batch_modifier')
|
9
|
-
require('defmastership/change_ref_modifier')
|
10
9
|
require('defmastership/comment_filter')
|
11
|
-
require('defmastership/constants')
|
12
|
-
require('defmastership/csv_formatter')
|
13
10
|
require('defmastership/definition')
|
14
11
|
require('defmastership/definition_parser')
|
15
12
|
require('defmastership/document')
|
13
|
+
require('defmastership/export/csv/formatter')
|
16
14
|
require('defmastership/filters')
|
17
|
-
require('defmastership/
|
18
|
-
require('defmastership/
|
19
|
-
require('defmastership/
|
20
|
-
require('defmastership/
|
21
|
-
require('defmastership/
|
15
|
+
require('defmastership/modifier/change_ref')
|
16
|
+
require('defmastership/modifier/factory')
|
17
|
+
require('defmastership/modifier/rename_included_files')
|
18
|
+
require('defmastership/modifier/update_def_checksum')
|
19
|
+
require('defmastership/modifier/update_def_version')
|
@@ -3,19 +3,19 @@
|
|
3
3
|
|
4
4
|
require('defmastership/batch_modifier')
|
5
5
|
|
6
|
-
module
|
6
|
+
module Defmastership
|
7
7
|
# Modifier example
|
8
|
-
class
|
8
|
+
class Toto
|
9
9
|
include Modifier
|
10
10
|
end
|
11
11
|
|
12
12
|
# Modifier example
|
13
|
-
class
|
13
|
+
class TuTu
|
14
14
|
include Modifier
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
RSpec.describe(
|
18
|
+
RSpec.describe(Defmastership::BatchModifier) do
|
19
19
|
subject(:batchmodifier) do
|
20
20
|
described_class.new(config, adoc_sources)
|
21
21
|
end
|
@@ -45,7 +45,7 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
45
45
|
|
46
46
|
describe '#apply' do
|
47
47
|
context 'with only one modification' do
|
48
|
-
let(:toto1) { instance_double(
|
48
|
+
let(:toto1) { instance_double(Defmastership::Modifier::Toto, 'toto1') }
|
49
49
|
let(:adoc_sources_modified) do
|
50
50
|
{
|
51
51
|
'file1.adoc' => 'some text modified',
|
@@ -62,7 +62,7 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
before do
|
65
|
-
allow(
|
65
|
+
allow(Defmastership::Modifier::Toto).to(receive(:new).once.and_return(toto1))
|
66
66
|
allow(toto1).to(receive(:do_modifications).once.and_return(adoc_sources_modified))
|
67
67
|
allow(toto1).to(receive(:config).once.and_return(p: 'modified_param'))
|
68
68
|
allow(toto1).to(receive(:changes).once.and_return([%w[from1 to1], %w[from2 to2]]))
|
@@ -70,7 +70,7 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it do
|
73
|
-
expect(
|
73
|
+
expect(Defmastership::Modifier::Toto).to(have_received(:new).with(p: 1))
|
74
74
|
end
|
75
75
|
|
76
76
|
it { expect(toto1).to(have_received(:do_modifications).with(adoc_sources)) }
|
@@ -82,8 +82,8 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
context 'with two modifications' do
|
85
|
-
let(:toto2) { instance_double(
|
86
|
-
let(:tutu3) { instance_double(
|
85
|
+
let(:toto2) { instance_double(Defmastership::Modifier::Toto, 'toto2') }
|
86
|
+
let(:tutu3) { instance_double(Defmastership::Modifier::TuTu, 'tutu3') }
|
87
87
|
|
88
88
|
let(:config_modified) do
|
89
89
|
{
|
@@ -94,10 +94,10 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
before do
|
97
|
-
allow(
|
97
|
+
allow(Defmastership::Modifier::Toto).to(receive(:new).once.and_return(toto2))
|
98
98
|
allow(toto2).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod2))
|
99
99
|
allow(toto2).to(receive(:config).once.and_return(:whatever))
|
100
|
-
allow(
|
100
|
+
allow(Defmastership::Modifier::TuTu).to(receive(:new).once.and_return(tutu3))
|
101
101
|
allow(tutu3).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod3))
|
102
102
|
allow(tutu3).to(receive(:config).once.and_return(:pouet))
|
103
103
|
allow(toto2).to(receive(:changes).once.and_return([%w[from1 to1]]))
|
@@ -105,8 +105,8 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
105
105
|
batchmodifier.apply(%i[modifier2 modifier3])
|
106
106
|
end
|
107
107
|
|
108
|
-
it { expect(
|
109
|
-
it { expect(
|
108
|
+
it { expect(Defmastership::Modifier::Toto).to(have_received(:new).with(p: 'whatever1')) }
|
109
|
+
it { expect(Defmastership::Modifier::TuTu).to(have_received(:new).with(p1: 'whatever2', p2: 'whatever3')) }
|
110
110
|
it { expect(toto2).to(have_received(:do_modifications).with(adoc_sources)) }
|
111
111
|
it { expect(toto2).to(have_received(:config).with(no_args)) }
|
112
112
|
it { expect(tutu3).to(have_received(:do_modifications).with(:adoc_sources_modified_mod2)) }
|