defmastership-core 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a2409414409c0de765bc37b9b666c32e31ec11fc6c5b5a03c44bc88c1d575d31
4
+ data.tar.gz: e2db2622f4b8eece83f5b1c80f918890619dc0d7a88c4b32cd35b90a6560afa3
5
+ SHA512:
6
+ metadata.gz: 75804159eff5802621ef51db560c7fac277b025d2eeb28462af0915c467aa2b927eb745c9aa20029056974e1d4c8bc7cb61deffe53c064b6f3da32e26128b769
7
+ data.tar.gz: f79713179f65c5c7e57eac2cbcf623b0a151a91a58de39d6953ef1803369c081429039c1eb200a52f312265fffc03a5999ed3de4b227f4797c84a73005367138
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *~
2
+ /tmp
3
+ /coverage
4
+ /Gemfile.lock
5
+ /pkg/
6
+ /.ruby-version
7
+ /doc/
8
+ /.yardoc/
9
+ /rspec_results.html
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,68 @@
1
+ default:
2
+ image: ruby:3.3
3
+ before_script:
4
+ - apt-get update
5
+ - ruby -v
6
+ - which ruby
7
+ - gem install bundler --no-document
8
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
9
+ - git config --global user.email "you@example.com"
10
+ - git config --global user.name "Your Name"
11
+
12
+ unit tests:
13
+ script:
14
+ - bundle exec rake test:spec
15
+ artifacts:
16
+ paths:
17
+ - rspec_results.html
18
+ - coverage/*
19
+
20
+ code_quality:
21
+ script:
22
+ - bundle exec rake quality:all
23
+
24
+ yard documentation:
25
+ script:
26
+ - bundle exec rake yard
27
+ artifacts:
28
+ paths:
29
+ - doc
30
+
31
+ unit tests ruby2.7:
32
+ image: ruby:2.7
33
+ before_script:
34
+ - apt-get update
35
+ - ruby -v
36
+ - which ruby
37
+ - gem install bundler -v 2.4.22 --no-document
38
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
39
+ script:
40
+ - bundle exec rake test:spec
41
+
42
+ unit tests ruby3.0:
43
+ image: ruby:3.0
44
+ script:
45
+ - bundle exec rake test:spec
46
+
47
+ unit tests ruby3.1:
48
+ image: ruby:3.1
49
+ script:
50
+ - bundle exec rake test:spec
51
+
52
+ unit tests ruby3.2:
53
+ image: ruby:3.2
54
+ script:
55
+ - bundle exec rake test:spec
56
+
57
+ pages:
58
+ stage: deploy
59
+ script:
60
+ - mkdir public
61
+ - cp -r doc/* public
62
+ - cp "rspec_results.html" public
63
+ - cp -r "coverage" public
64
+ artifacts:
65
+ paths:
66
+ - public
67
+ only:
68
+ - master
data/Gemfile ADDED
@@ -0,0 +1,88 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ source 'https://rubygems.org'
5
+
6
+ gemspec
7
+
8
+ ruby RUBY_VERSION
9
+
10
+ # rubocop:disable Metrics/BlockLength
11
+ group :development do
12
+ # needed by yard to render documentation
13
+ gem 'asciidoctor', '~> 2'
14
+ # cucumber steps for command line tests
15
+ gem 'aruba', '~> 2'
16
+ # bdd
17
+ gem 'cucumber', '~> 9'
18
+
19
+ # code duplication
20
+ gem 'flay', '~> 2'
21
+
22
+ # automatic test run
23
+ gem 'guard', '~> 2'
24
+ # automatic update invocation
25
+ gem 'guard-bundler', '~> 3'
26
+ if RUBY_VERSION >= '3.0'
27
+ # automatic style check
28
+ gem 'guard-reek', '~> 1.2'
29
+ end
30
+ # automatic tdd
31
+ gem 'guard-rspec', '~> 4'
32
+ # automatic style check
33
+ gem 'guard-rubocop', '~> 1'
34
+
35
+ # if RUBY_VERSION >= '3.0'
36
+ # # mutation testing
37
+ # plan = 'oss'
38
+ # key = '7oac4dMz95cTUuFPtGDfTDSQep6ZhdGW'
39
+ # source "https://#{plan}:#{key}@gem.mutant.dev" do
40
+ # # license needed
41
+ # gem 'mutant-license', '~> 0'
42
+ # end
43
+ # # mutation testing
44
+ # gem 'mutant-rspec', '~> 0'
45
+ # end
46
+ # to parse and execute Rakefile
47
+ gem 'rake', '~> 13'
48
+
49
+ if RUBY_VERSION >= '3.0'
50
+ # needed by yard to render documentation
51
+ gem 'rdoc', '~> 6'
52
+ end
53
+ # tdd
54
+ gem 'rspec', '~> 3'
55
+ # # to test performances
56
+ # gem 'rspec-benchmark', '~> 0'
57
+ # code needs to be clean
58
+ gem 'rubocop', '1.68'
59
+ # code needs to be clean
60
+ gem 'rubocop-performance', '~> 1'
61
+ # test code needs to be clean
62
+ gem 'rubocop-rspec', '~> 3'
63
+ # Rakefiles need to be clean
64
+ gem 'rubocop-rake', '~> 0'
65
+
66
+ if RUBY_VERSION >= '3.0'
67
+ # detect selling code
68
+ gem 'reek', '~> 6'
69
+ # my code needs to be critiqued
70
+ gem 'rubycritic', '~> 4'
71
+ # Doc need to be clean
72
+ gem 'rubocop-yard', '~> 0'
73
+ end
74
+
75
+ # What is tdd without code coverage ?
76
+ gem 'simplecov', '~> 0'
77
+
78
+ if RUBY_VERSION >= '3.0'
79
+ # to document code
80
+ gem 'yard', '~> 0'
81
+ end
82
+ end
83
+ # rubocop:enable Metrics/BlockLength
84
+
85
+ group :debugging do
86
+ # Sometimes, we need to debug
87
+ gem 'pry', '~> 0'
88
+ end
data/Guardfile ADDED
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2024 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ # notifications :emacs
5
+
6
+ guard :bundler do
7
+ require 'guard/bundler'
8
+ require 'guard/bundler/verify'
9
+ helper = Guard::Bundler::Verify.new
10
+
11
+ files = ['Gemfile']
12
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
13
+
14
+ # Assume files are symlinked from somewhere
15
+ files.each { |file| watch(helper.real_path(file)) }
16
+ end
17
+
18
+ guard :rspec, cmd: 'bundle exec rspec --options config/rspec' do
19
+ require 'guard/rspec/dsl'
20
+ dsl = Guard::RSpec::Dsl.new(self)
21
+
22
+ # RSpec files
23
+ rspec = dsl.rspec
24
+ watch(rspec.spec_helper) { rspec.spec_dir }
25
+ watch(rspec.spec_support) { rspec.spec_dir }
26
+ watch(rspec.spec_files)
27
+
28
+ # Ruby files
29
+ ruby = dsl.ruby
30
+ dsl.watch_spec_files_for(ruby.lib_files)
31
+ end
32
+
33
+ guard :rubocop,
34
+ all_on_start: true,
35
+ cli: ['--display-cop-names', '--config=config/rubocop.yml'] do
36
+ watch(/.+\.rb$/)
37
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m.first) }
38
+ end
39
+
40
+ guard :reek,
41
+ cli: ['--config config/reek.yml', '--single-line'] do
42
+ watch(/.+\.rb$/)
43
+ watch('config/reek.yml')
44
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Jérôme Arbez-Gindre, and the individual contributors
4
+ to DefMastership.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.adoc ADDED
@@ -0,0 +1,8 @@
1
+ = defmastership-core
2
+
3
+ == Features
4
+
5
+ * Some classes/constants used by both asciidoctor-defmastership and defmastership itself
6
+
7
+
8
+
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('rake/clean')
5
+
6
+ Dir['tasks/**/*.rake'].each { |t| load t }
7
+
8
+ desc 'Continous integration tasks'
9
+ task :ci do
10
+ [
11
+ 'test:spec',
12
+ :rubocop
13
+ ].each do |name|
14
+ puts "\n=== Running #{name}...\n"
15
+ Rake::Task[name].invoke
16
+ puts "\n=== Running #{name} -> Done\n"
17
+ end
18
+ end
19
+
20
+ task default: :ci
data/config/mutant.yml ADDED
@@ -0,0 +1,30 @@
1
+ ---
2
+ usage: opensource
3
+ includes:
4
+ - lib
5
+ integration:
6
+ name: rspec
7
+ arguments:
8
+ - --options=config/rspec
9
+ - spec
10
+ requires:
11
+ - defmastership
12
+ matcher:
13
+ subjects:
14
+ - 'DefMastership*'
15
+ # ignore:
16
+ # - 'DefMastership::BatchModifier*'
17
+ # - 'DefMastership::Export::CSV::Formatter*'
18
+ # - 'DefMastership::Export::CSV::BodyFormatter*'
19
+ # - 'DefMastership::Export::CSV::HeaderFormatter*'
20
+ # - 'DefMastership::Modifier::ChangeRef*'
21
+ # - 'DefMastership::Definition*'
22
+ # - 'DefMastership::Document*'
23
+ # - 'DefMastership::Modifier::ModifierCommon*'
24
+ # - 'DefMastership::Modifier::Factory*'
25
+ # - 'DefMastership::ParsingState*'
26
+ # - 'DefMastership::Modifier::RenameIncludedFiles*'
27
+ # - 'DefMastership::Modifier::UpdateDefChecksum*'
28
+ # - 'DefMastership::Modifier::UpdateDef*'
29
+ # - 'DefMastership::Modifier::UpdateDefVersion*'
30
+ # fail_fast: true
data/config/reek.yml ADDED
@@ -0,0 +1,130 @@
1
+ ---
2
+ # detectors:
3
+ # Attribute:
4
+ # enabled: true
5
+ # exclude: []
6
+ # BooleanParameter:
7
+ # enabled: true
8
+ # exclude: []
9
+ # ClassVariable:
10
+ # enabled: true
11
+ # exclude: []
12
+ # ControlParameter:
13
+ # enabled: true
14
+ # exclude: []
15
+ # DataClump:
16
+ # enabled: true
17
+ # exclude: []
18
+ # max_copies: 2
19
+ # min_clump_size: 2
20
+ # DuplicateMethodCall:
21
+ # enabled: true
22
+ # exclude: []
23
+ # max_calls: 1
24
+ # allow_calls: []
25
+ # FeatureEnvy:
26
+ # enabled: true
27
+ # exclude: []
28
+ # InstanceVariableAssumption:
29
+ # enabled: true
30
+ # exclude: []
31
+ # IrresponsibleModule:
32
+ # enabled: true
33
+ # exclude: []
34
+ # LongParameterList:
35
+ # enabled: true
36
+ # exclude: []
37
+ # max_params: 3
38
+ # overrides:
39
+ # initialize:
40
+ # max_params: 5
41
+ # LongYieldList:
42
+ # enabled: true
43
+ # exclude: []
44
+ # max_params: 3
45
+ # ManualDispatch:
46
+ # enabled: true
47
+ # exclude: []
48
+ # MissingSafeMethod:
49
+ # enabled: true
50
+ # exclude: []
51
+ # ModuleInitialize:
52
+ # enabled: true
53
+ # exclude: []
54
+ # NestedIterators:
55
+ # enabled: true
56
+ # exclude: []
57
+ # max_allowed_nesting: 1
58
+ # ignore_iterators:
59
+ # - tap
60
+ # - Tempfile.create
61
+ # NilCheck:
62
+ # enabled: true
63
+ # exclude: []
64
+ # RepeatedConditional:
65
+ # enabled: true
66
+ # exclude: []
67
+ # max_ifs: 2
68
+ # SubclassedFromCoreClass:
69
+ # enabled: true
70
+ # exclude: []
71
+ # TooManyConstants:
72
+ # enabled: true
73
+ # exclude: []
74
+ # max_constants: 5
75
+ # TooManyInstanceVariables:
76
+ # enabled: true
77
+ # exclude: []
78
+ # max_instance_variables: 4
79
+ # TooManyMethods:
80
+ # enabled: true
81
+ # exclude: []
82
+ # max_methods: 15
83
+ # TooManyStatements:
84
+ # enabled: true
85
+ # exclude:
86
+ # - initialize
87
+ # max_statements: 5
88
+ # UncommunicativeMethodName:
89
+ # enabled: true
90
+ # exclude: []
91
+ # reject:
92
+ # - "/^[a-z]$/"
93
+ # - "/[0-9]$/"
94
+ # - "/[A-Z]/"
95
+ # accept: []
96
+ # UncommunicativeModuleName:
97
+ # enabled: true
98
+ # exclude: []
99
+ # reject:
100
+ # - "/^.$/"
101
+ # - "/[0-9]$/"
102
+ # accept: []
103
+ # UncommunicativeParameterName:
104
+ # enabled: true
105
+ # exclude: []
106
+ # reject:
107
+ # - "/^.$/"
108
+ # - "/[0-9]$/"
109
+ # - "/[A-Z]/"
110
+ # - "/^_/"
111
+ # accept: []
112
+ # UncommunicativeVariableName:
113
+ # enabled: true
114
+ # exclude: []
115
+ # reject:
116
+ # - "/^.$/"
117
+ # - "/[0-9]$/"
118
+ # - "/[A-Z]/"
119
+ # accept:
120
+ # - "/^_$/"
121
+ # UnusedParameters:
122
+ # enabled: true
123
+ # exclude: []
124
+ # UnusedPrivateMethod:
125
+ # enabled: false
126
+ # exclude: []
127
+ # UtilityFunction:
128
+ # enabled: true
129
+ # exclude: []
130
+ # public_methods_only: false
data/config/rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --format html --out rspec_results.html
3
+ --color
4
+ --require spec_helper
@@ -0,0 +1,89 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
11
+
12
+ require:
13
+ - rubocop-performance
14
+ - rubocop-rspec
15
+ - rubocop-rake
16
+ - rubocop-yard
17
+
18
+ AllCops:
19
+ TargetRubyVersion: 2.7
20
+ EnabledByDefault: true
21
+ DisplayCopNames: true
22
+
23
+ Style/Copyright:
24
+ Enabled: true
25
+ Notice: 'Copyright (\(c\) )?202[0-9] Jerome Arbez-Gindre'
26
+ AutocorrectNotice: '# Copyright (c) 2023 Jerome Arbez-Gindre'
27
+
28
+ Lint/ConstantResolution: # Not available ins rubocop 0.81
29
+ Enabled: false
30
+
31
+ Style/DocumentationMethod:
32
+ Enabled: false
33
+
34
+ Style/StringHashKeys :
35
+ Enabled: true
36
+ Exclude:
37
+ - '*.gemspec'
38
+ - 'spec/unit/def_mastership/batch_modifier_spec.rb'
39
+ - 'spec/unit/def_mastership/modifier/update_def_checksum_spec.rb'
40
+ - 'spec/unit/def_mastership/modifier/update_def_spec.rb'
41
+ - 'spec/unit/def_mastership/modifier/update_def_version_spec.rb'
42
+
43
+ Style/MissingElse:
44
+ EnforcedStyle: case
45
+
46
+ Metrics/ModuleLength :
47
+ Exclude:
48
+ - 'spec/**/*'
49
+
50
+ Metrics/BlockLength :
51
+ Exclude:
52
+ - 'spec/**/*'
53
+ - '*.gemspec'
54
+
55
+ Security/Eval :
56
+ Exclude:
57
+ - 'Rakefile'
58
+
59
+ Style/ConstantVisibility :
60
+ Exclude:
61
+ # there is one unique explicit constant visibility for all
62
+ # constants
63
+ - 'lib/defmastership/constants.rb'
64
+
65
+ # rubocop-rspec options
66
+ RSpec/MessageExpectation :
67
+ Enabled: true
68
+
69
+ RSpec/SpecFilePathFormat :
70
+ Enabled: true
71
+
72
+ RSpec/SpecFilePathSuffix :
73
+ Enabled: true
74
+
75
+ RSpec/NestedGroups:
76
+ Max: 4
77
+
78
+ Layout/RedundantLineBreak:
79
+ Enabled: false
80
+
81
+ Style/DisableCopsWithinSourceCodeDirective:
82
+ Enabled: true
83
+ Exclude:
84
+ - 'Gemfile'
85
+ - 'tasks/code_quality.rake'
86
+
87
+ Layout/EndOfLine:
88
+ EnforcedStyle: lf
89
+
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ # Ensure we require the local version and not one we might have
5
+ # installed already
6
+ require(
7
+ File.join(
8
+ [
9
+ File.dirname(__FILE__),
10
+ 'lib',
11
+ 'defmastership',
12
+ 'core',
13
+ 'version.rb'
14
+ ]
15
+ )
16
+ )
17
+
18
+ Gem::Specification.new do |spec|
19
+ spec.metadata = {
20
+ 'rubygems_mfa_required' => 'true'
21
+ }
22
+ spec.required_ruby_version = '>= 2.7'
23
+ spec.name = 'defmastership-core'
24
+ spec.version = DefMastership::Core::VERSION
25
+ spec.author = 'Jérôme Arbez-Gindre'
26
+ spec.email = 'jeromearbezgindre@gmail.com'
27
+ spec.licenses = ['MIT']
28
+ spec.homepage = 'https://gitlab.com/defmastership/defmastership-core/'
29
+ spec.platform = Gem::Platform::RUBY
30
+ spec.summary = 'Handling of references and definitions with asciidoctor - common code'
31
+ spec.files = `git ls-files`.split("\n")
32
+ spec.require_paths << 'lib'
33
+ end
@@ -0,0 +1,124 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Common code for DefMastership and Asciidoctor::DefMastership
6
+ module Core
7
+ # set of regexp of added asciidoctor constructions
8
+ # This module smells of :reek:TooManyConstants
9
+ module DMRegexp
10
+ # [Regexp] to match a single line comment
11
+ SINGLE_LINE_COMMENT = %r{^//[^/]}.freeze
12
+ public_constant :SINGLE_LINE_COMMENT
13
+
14
+ # [Regexp] match all text before the definition's reference
15
+ DEF_BEFORE_REF = <<~'BEF'
16
+ ^\s*
17
+ \[\s*define\s*,
18
+ \s*(?<type>[\w:_-]+)\s*,
19
+ \s*
20
+ BEF
21
+ public_constant :DEF_BEFORE_REF
22
+
23
+ # [Regexp] match all text after the definition's reference
24
+ DEF_AFTER_REF = <<~'AFT'
25
+ \s*
26
+ (,\s*\[\s*(?<labels>.*?)\s*\])?\s*\]
27
+ AFT
28
+ public_constant :DEF_AFTER_REF
29
+
30
+ # [Regexp] match optional explicit version and explicit checksum
31
+ DEF_VERSION_AND_CHECKSUM = '(?<version_and_checksum>' \
32
+ '\((?<explicit_version>[^~]+)?(?<explicit_checksum>~[[:alnum:]]+)?\)' \
33
+ ')?'
34
+ public_constant :DEF_VERSION_AND_CHECKSUM
35
+
36
+ # [Regexp] match reference
37
+ REFERENCE = '(?<reference>[\\w:_-]+)'
38
+ public_constant :REFERENCE
39
+
40
+ # [Regexp] match a definition line
41
+ DEFINITION = Regexp.new(
42
+ "#{DEF_BEFORE_REF}#{REFERENCE}#{DEF_VERSION_AND_CHECKSUM}#{DEF_AFTER_REF}",
43
+ Regexp::EXTENDED
44
+ )
45
+ public_constant :DEFINITION
46
+
47
+ # [Regexp] match a asciidcotor attribute definition
48
+ VARIABLE_DEF = /^\s*:(?<varname>[\w:_-]+):\s+
49
+ (?<value>\S.*\S)\s*$/x.freeze
50
+ public_constant :VARIABLE_DEF
51
+
52
+ # [Regexp] match a asciidcotor attribute use
53
+ VARIABLE_USE = /{(?<varname>[\w:_-]+)}/x.freeze
54
+ public_constant :VARIABLE_USE
55
+
56
+ # [Regexp] match an external cross reference type configuration
57
+ EREF_CONFIG = /^\s*:eref-(?<reference>[\w:_-]+)-(?<symb>prefix|url):\s*
58
+ \s*(?<value>\S.*\S)\s*/x.freeze
59
+ public_constant :EREF_CONFIG
60
+ # [Regexp] match an external cross reference use
61
+ EREF_DEF = /^\s*
62
+ defs:eref\[
63
+ \s*(?<reference>[\w:_-]+)\s*,
64
+ \s*\[\s*(?<extrefs>[^\]]+?)\s*\]\s*\]/x.freeze
65
+ public_constant :EREF_DEF
66
+
67
+ # [Regexp] match an asciidoc block delimiter
68
+ BLOCK = /^--\s*$/.freeze
69
+ public_constant :BLOCK
70
+
71
+ # [Regexp] match the begining of an internal cross reference
72
+ IREF_DEF_BEF = 'defs:iref\[\s*'
73
+ public_constant :IREF_DEF_BEF
74
+ # [Regexp] match the end of an internal cross reference
75
+ IREF_DEF_AFT = '\s*\]'
76
+ public_constant :IREF_DEF_AFT
77
+ # [Regexp] match an internal cross reference
78
+ IREF_DEF = Regexp.new(
79
+ "#{IREF_DEF_BEF}(?<intref>[\\w:_-]+)#{IREF_DEF_AFT}",
80
+ Regexp::EXTENDED
81
+ )
82
+ public_constant :IREF_DEF
83
+
84
+ # [Regexp] match an attribute configuration
85
+ ATTR_CONFIG = /\s*:attr-(?<attr>[\w:_-]+)-prefix:
86
+ \s+(?<prefix>.+?)\s*$/x.freeze
87
+ public_constant :ATTR_CONFIG
88
+ # [Regexp] match an attribute use
89
+ ATTR_SET = /\s*
90
+ defs:attribute\[
91
+ \s*(?<attr>[\w:_-]+)\s*,
92
+ \s*(?<value>.+?)\s*\]/x.freeze
93
+ public_constant :ATTR_SET
94
+
95
+ # [Regexp] match an empty line
96
+ EMPTY_LINE = /^\s*$/.freeze
97
+ public_constant :EMPTY_LINE
98
+
99
+ # [Regexp] match everything
100
+ WHATEVER = //.freeze
101
+ public_constant :WHATEVER
102
+
103
+ # [Regexp] match asciidoc include statement keyword
104
+ INCLUDE_KEYWORD = '\binclude::'
105
+ public_constant :INCLUDE_KEYWORD
106
+ # [Regexp] match asciidoc include statement path
107
+ INCLUDE_PATH = '(?<path>.*/)?'
108
+ public_constant :INCLUDE_PATH
109
+ # [Regexp] match asciidoc include statement filename
110
+ INCLUDE_FILENAME = '(?<filename>[^\\/]+)'
111
+ public_constant :INCLUDE_FILENAME
112
+ # [Regexp] match asciidoc include statement options
113
+ INCLUDE_OPTIONS = '\[(?<options>[^\]]*)\]'
114
+ public_constant :INCLUDE_OPTIONS
115
+
116
+ # [Regexp] match asciidoc include statement
117
+ INCLUDE = Regexp.new(
118
+ INCLUDE_KEYWORD + INCLUDE_PATH + INCLUDE_FILENAME + INCLUDE_OPTIONS,
119
+ Regexp::EXTENDED
120
+ )
121
+ public_constant :INCLUDE
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ module Core
6
+ # Allow to know if we need to parse the line or simply ignore it
7
+ class ParsingState
8
+ # mutant:disable (for mutant, aatribute initialization is useless)
9
+ def initialize
10
+ @last_disabling_line = nil
11
+ end
12
+
13
+ def enabled?(line)
14
+ return false if line.match?(DMRegexp::SINGLE_LINE_COMMENT)
15
+
16
+ line = line.chomp
17
+ possibly_invert_last_disabling_line(line) if ['....', '----', '////'].include?(line)
18
+
19
+ !@last_disabling_line
20
+ end
21
+
22
+ private
23
+
24
+ def possibly_invert_last_disabling_line(line)
25
+ if @last_disabling_line == line
26
+ @last_disabling_line = nil
27
+ elsif !@last_disabling_line
28
+ @last_disabling_line = line
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Common to defmastership and asciidoctor-defmastership
6
+ module Core
7
+ # [String] Gem version
8
+ VERSION = '1.0.0'
9
+ public_constant :VERSION
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/core/version')
5
+
6
+ # Add requires for other files you add to your project here, so
7
+ # you just need to require this one file in your bin file
8
+ require('defmastership/core/constants')
9
+ require('defmastership/core/parsing_state')
@@ -0,0 +1,29 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('simplecov')
5
+
6
+ SimpleCov.start do
7
+ command_name 'spec:unit'
8
+
9
+ add_group 'Libraries', 'lib'
10
+ add_group 'Unit test', 'spec/unit'
11
+
12
+ add_filter 'config'
13
+ add_filter 'vendor'
14
+ add_filter 'set_join_hack'
15
+
16
+ minimum_coverage 100
17
+
18
+ enable_coverage :branch
19
+ end
20
+
21
+ RSpec::Matchers.define(:matchdata_including) do |h|
22
+ match do |matchdata|
23
+ h.all? do |key, _|
24
+ matchdata[key] == h[key]
25
+ end
26
+ end
27
+ end
28
+
29
+ require('defmastership')
@@ -0,0 +1,62 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/core/parsing_state')
5
+
6
+ RSpec.describe(DefMastership::Core::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
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ RSpec.describe(DefMastership::Core) do
5
+ it 'has a version number' do
6
+ expect(DefMastership::Core::VERSION).not_to(be_nil)
7
+ end
8
+ end
@@ -0,0 +1,74 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ # rubocop:disable Metrics/BlockLength
5
+ namespace 'quality' do
6
+ begin
7
+ require('rubocop/rake_task')
8
+
9
+ RuboCop::RakeTask.new do |task|
10
+ task.options << '--display-cop-names'
11
+ task.options << '--config=config/rubocop.yml'
12
+ end
13
+ rescue LoadError
14
+ task(:rubocop) do
15
+ puts('Install rubocop to run its rake tasks')
16
+ end
17
+ end
18
+
19
+ begin
20
+ require('reek/rake/task')
21
+
22
+ Reek::Rake::Task.new do |task|
23
+ task.fail_on_error = true
24
+ task.source_files = '{lib,spec}/**/*.rb'
25
+ task.reek_opts = '--config config/reek.yml --single-line'
26
+ end
27
+ rescue LoadError
28
+ task(:reek) do
29
+ puts('Install reek to run its rake tasks')
30
+ end
31
+ end
32
+
33
+ begin
34
+ require('flay_task')
35
+
36
+ FlayTask.new(:flay, 200, %w[bin lib]) do |task|
37
+ task.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task(:flay) do
41
+ puts('Install flay to run its rake tasks')
42
+ end
43
+ end
44
+
45
+ begin
46
+ require('rubycritic/rake_task')
47
+
48
+ RubyCritic::RakeTask.new do |task|
49
+ task.verbose = true
50
+ task.options = '--no-browser'
51
+ end
52
+ rescue LoadError
53
+ task(:rubycritic) do
54
+ puts('Install rubycritic to run its rake tasks')
55
+ end
56
+ end
57
+
58
+ desc 'Runs all quality code check'
59
+ task(
60
+ all: [
61
+ 'quality:rubocop',
62
+ 'quality:reek',
63
+ 'quality:flay',
64
+ 'quality:rubycritic'
65
+ ]
66
+ )
67
+ end
68
+ # rubocop:enable Metrics/BlockLength
69
+
70
+ desc 'Synonym for quality:rubocop'
71
+ task(rubocop: 'quality:rubocop')
72
+
73
+ desc 'Synonym for quality:reek'
74
+ task(reek: 'quality:reek')
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ desc 'Starts the interactive console'
5
+ task :console do
6
+ require 'pry'
7
+ Pry.start
8
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2024 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ namespace 'documentation' do
5
+ require('yard')
6
+
7
+ YARD::Rake::YardocTask.new do |task|
8
+ task.files = ['lib/**/*.rb']
9
+ task.options = ['--fail-on-warning', '--verbose']
10
+ task.stats_options = ['--list-undoc']
11
+ end
12
+ rescue LoadError
13
+ task(:yard) do
14
+ puts('Install Yard to run its rake tasks')
15
+ end
16
+ end
17
+
18
+ desc 'Synonym for documentation:yard'
19
+ task(yard: 'documentation:yard')
@@ -0,0 +1,4 @@
1
+ # Copyright (c) 2024 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('bundler/gem_tasks')
data/tasks/test.rake ADDED
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('rspec/core/rake_task')
5
+
6
+ namespace 'test' do
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = ['--options config/rspec']
9
+ end
10
+
11
+ desc 'Runs all unit tests'
12
+ task(all: ['test:spec'])
13
+ end
14
+
15
+ desc 'Synonym for test:spec'
16
+ task(spec: 'test:spec')
17
+
18
+ desc 'Synonym for test:all'
19
+ task(test: 'test:all')
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: defmastership-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jérôme Arbez-Gindre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: jeromearbezgindre@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - ".gitlab-ci.yml"
21
+ - Gemfile
22
+ - Guardfile
23
+ - LICENSE
24
+ - README.adoc
25
+ - Rakefile
26
+ - config/mutant.yml
27
+ - config/reek.yml
28
+ - config/rspec
29
+ - config/rubocop.yml
30
+ - defmastership-core.gemspec
31
+ - lib/defmastership.rb
32
+ - lib/defmastership/core/constants.rb
33
+ - lib/defmastership/core/parsing_state.rb
34
+ - lib/defmastership/core/version.rb
35
+ - spec/spec_helper.rb
36
+ - spec/unit/def_mastership/core/parsing_state_spec.rb
37
+ - spec/unit/def_mastership/core_spec.rb
38
+ - tasks/code_quality.rake
39
+ - tasks/console.rake
40
+ - tasks/documentation.rake
41
+ - tasks/package.rake
42
+ - tasks/test.rake
43
+ homepage: https://gitlab.com/defmastership/defmastership-core/
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ rubygems_mfa_required: 'true'
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '2.7'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.5.23
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Handling of references and definitions with asciidoctor - common code
68
+ test_files: []