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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6075e9ff9eb3bb1d4080344f8288946ed3ae008c0ef7c943e558417ac1922084
4
- data.tar.gz: 2707d0ef2c7ac04eb6fb5ff07362584243c3f8d7661a9e7f617d8239b79d162d
3
+ metadata.gz: 57c8ecae1a1c2e304a23c513b3a65b6c112da30ccaf75fb7f137f9247e9db36c
4
+ data.tar.gz: 2730ff7b5ef8838d4a131f182099479935ab347f0505b3a5518e6561bc30eb8c
5
5
  SHA512:
6
- metadata.gz: 6670fef12836200db63e7bff8eec4afd5dad49e53a1d873b84816572933ca7fee2364076691f4e55d7858e3a49398b34d601f1c1ba6a7f05b9a8628b393acc03
7
- data.tar.gz: e0169b605d73381d402c932cdd6387cb06cca5287364735c4a95c5fe5087845a24b4bc62018a87676510520db5ea6d656b4e1a9cb2e8586b772f6c0deae7f87f
6
+ metadata.gz: d4832d0e97edd679f51fe2223bf8eabe28c8e8e2dc14b9b994c055d24c31e14547b3db9fdb962abd843c86d9c370af1c3d3e662a52833260fc0b40b61f70ba7d
7
+ data.tar.gz: fdbfa9b7b031f10129cb5a7e12c9d3aee542ee86d1f56f406a3e05bd17297a20e99a8ec1ddf537bd61e2f128a0d6d764bdd47659d48e2c9e8166b603bc1ca6df
data/.gitignore CHANGED
@@ -6,3 +6,6 @@ defmastership-0.0.1.gem
6
6
  /Gemfile.lock
7
7
  /pkg/
8
8
  /.ruby-version
9
+ /doc/
10
+ /.yardoc/
11
+ /whatever
data/.gitlab-ci.yml CHANGED
@@ -12,15 +12,29 @@ default:
12
12
  bdd:
13
13
  script:
14
14
  - bundle exec rake test:features
15
+ artifacts:
16
+ paths:
17
+ - features_results.html
15
18
 
16
19
  unit tests:
17
20
  script:
18
21
  - bundle exec rake test:spec
22
+ artifacts:
23
+ paths:
24
+ - rspec_results.html
25
+ - coverage/*
19
26
 
20
27
  code_quality:
21
28
  script:
22
29
  - bundle exec rake quality:all
23
30
 
31
+ yard documentation:
32
+ script:
33
+ - bundle exec rake yard
34
+ artifacts:
35
+ paths:
36
+ - doc
37
+
24
38
  bdd ruby2.7:
25
39
  image: ruby:2.7
26
40
  before_script:
@@ -75,3 +89,16 @@ unit tests ruby3.2:
75
89
  script:
76
90
  - bundle exec rake test:spec
77
91
 
92
+ pages:
93
+ stage: deploy
94
+ script:
95
+ - mkdir public
96
+ - cp -r doc/* public
97
+ - cp "features_results.html" public
98
+ - cp "rspec_results.html" public
99
+ - cp -r "coverage" public
100
+ artifacts:
101
+ paths:
102
+ - public
103
+ only:
104
+ - master
data/Gemfile CHANGED
@@ -10,9 +10,9 @@ ruby RUBY_VERSION
10
10
  # rubocop:disable Metrics/BlockLength
11
11
  group :development do
12
12
  # cucumber steps for command line tests
13
- gem 'aruba', '~> 2.2'
13
+ gem 'aruba', '~> 2'
14
14
  # bdd
15
- gem 'cucumber', '~> 9.2'
15
+ gem 'cucumber', '~> 9'
16
16
 
17
17
  # code duplication
18
18
  gem 'flay', '~> 2'
@@ -36,40 +36,51 @@ group :development do
36
36
  key = '7oac4dMz95cTUuFPtGDfTDSQep6ZhdGW'
37
37
  source "https://#{plan}:#{key}@gem.mutant.dev" do
38
38
  # license needed
39
- gem 'mutant-license', '~> 0.1.1'
39
+ gem 'mutant-license', '~> 0'
40
40
  end
41
41
  # mutation testing
42
- gem 'mutant-rspec', '~> 0.11'
42
+ gem 'mutant-rspec', '~> 0'
43
43
  end
44
44
  # to parse and execute Rakefile
45
- gem 'rake', '~> 13.1'
45
+ gem 'rake', '~> 13'
46
+
47
+ if RUBY_VERSION >= '3.0'
48
+ # needed by yard to render documentation
49
+ gem 'rdoc', '~> 6'
50
+ end
46
51
  # tdd
47
- gem 'rspec', '~> 3.13'
52
+ gem 'rspec', '~> 3'
48
53
  # # to test performances
49
- # gem 'rspec-benchmark', '~> 0.6.0'
54
+ # gem 'rspec-benchmark', '~> 0'
50
55
  # code needs to be clean
51
- gem 'rubocop', '~> 1.65'
56
+ gem 'rubocop', '1.68'
52
57
  # code needs to be clean
53
- gem 'rubocop-performance', '~> 1.21'
58
+ gem 'rubocop-performance', '~> 1'
54
59
  # test code needs to be clean
55
- gem 'rubocop-rspec', '~> 3.0'
60
+ gem 'rubocop-rspec', '~> 3'
56
61
  # Rakefiles need to be clean
57
- gem 'rubocop-rake', '~> 0.6'
62
+ gem 'rubocop-rake', '~> 0'
63
+
58
64
  if RUBY_VERSION >= '3.0'
59
65
  # detect selling code
60
- gem 'reek', '~> 6.3'
66
+ gem 'reek', '~> 6'
61
67
  # my code needs to be critiqued
62
68
  gem 'rubycritic', '~> 4'
69
+ # Doc need to be clean
70
+ gem 'rubocop-yard', '~> 0'
63
71
  end
64
72
 
65
73
  # What is tdd without code coverage ?
66
- gem 'simplecov', '~> 0.22', '< 0.23'
67
- # # to document code
68
- # gem 'yard', '~> 0.9.5'
74
+ gem 'simplecov', '~> 0'
75
+
76
+ if RUBY_VERSION >= '3.0'
77
+ # to document code
78
+ gem 'yard', '~> 0'
79
+ end
69
80
  end
70
81
  # rubocop:enable Metrics/BlockLength
71
82
 
72
83
  group :debugging do
73
84
  # Sometimes, we need to debug
74
- gem 'pry', '~> 0.14'
85
+ gem 'pry', '~> 0'
75
86
  end
data/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright (c) 2020 Jérôme Arbez-Gindre, and the individual contributors
4
- to DefMastership.
4
+ to Defmastership.
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
data/README.adoc ADDED
@@ -0,0 +1,24 @@
1
+ = defmastership
2
+
3
+ == Features
4
+
5
+ * CSV export of https://gitlab.com/defmastership/asciidoctor-defmastership[asciidoctor-defmastership] statements.
6
+ * Automatic modifications of asciidoc files for : (See https://defmastership.gitlab.io/defmastership-example/defmastership-example.pdf/#_automatic_modifications[list of modifications].)
7
+ ** Computation of definitions reference ids
8
+ ** Explicit checksums updates
9
+ ** Explicit version updates (note: defmastership-examples not updated with last feature modification)
10
+
11
+ NOTE: depend on https://gitlab.com/defmastership/defmastership-core[defmastership-core]
12
+
13
+ == Development method
14
+
15
+ * BDD:
16
+ ** https://gitlab.com/defmastership/defmastership/-/tree/master/features[features].
17
+ ** https://defmastership.gitlab.io/defmastership/features_results.html[features_results.html]
18
+
19
+ * TDD:
20
+ ** https://gitlab.com/defmastership/defmastership/-/tree/master/spec/unit/defmastership?ref_type=heads[unit tests (rspec)]
21
+ ** https://defmastership.gitlab.io/defmastership/rspec_results.html[rspec_results.html]
22
+ ** https://defmastership.gitlab.io/defmastership/coverage[Unit tests coverage]
23
+
24
+
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
1
  # Copyright (c) 2023 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('bundler/gem_tasks')
5
4
  require('rake/clean')
6
5
 
7
6
  Dir['tasks/**/*.rake'].each { |t| load t }
data/bin/defmastership CHANGED
@@ -6,14 +6,14 @@ require('csv')
6
6
  require('defmastership')
7
7
  require('gli')
8
8
 
9
- module DefMastership
9
+ module Defmastership
10
10
  # The start of everything !
11
11
  class App
12
12
  extend GLI::App
13
13
 
14
14
  program_desc 'Tool to handle Asciidoctor definition extension'
15
15
 
16
- version DefMastership::VERSION
16
+ version Defmastership::VERSION
17
17
 
18
18
  subcommand_option_handling :normal
19
19
  arguments :strict
@@ -54,12 +54,12 @@ module DefMastership
54
54
  c.switch(%i[no-fail], desc: 'Exit succes even in case of wrong explicit checksum')
55
55
 
56
56
  c.action do |_global_options, options, args|
57
- my_doc = DefMastership::Document.new
57
+ my_doc = Defmastership::Document.new
58
58
  my_doc.parse_file_with_preprocessor(args.first)
59
59
 
60
60
  output_file = args.first.sub(/\.adoc$/, '.csv')
61
61
 
62
- DefMastership::CSVFormatter.new(my_doc, options['separator']).export_to(output_file)
62
+ Defmastership::Export::CSV::Formatter.new(my_doc, options['separator']).export_to(output_file)
63
63
 
64
64
  if my_doc.wrong_explicit_checksum?
65
65
  my_doc.definitions.each do |definition|
@@ -112,4 +112,4 @@ module DefMastership
112
112
  end
113
113
  end
114
114
 
115
- exit(DefMastership::App.run(ARGV))
115
+ exit(Defmastership::App.run(ARGV))
data/config/mutant.yml CHANGED
@@ -11,20 +11,22 @@ requires:
11
11
  - defmastership
12
12
  matcher:
13
13
  subjects:
14
- - 'DefMastership*'
15
- # ignore:
16
- # - 'DefMastership::BatchModifier*'
17
- # - 'DefMastership::CSVFormatter*'
18
- # - 'DefMastership::CSVFormatterBody*'
19
- # - 'DefMastership::CSVFormatterHeader*'
20
- # - 'DefMastership::ChangeRefModifier*'
21
- # - 'DefMastership::Definition*'
22
- # - 'DefMastership::Document*'
23
- # - 'DefMastership::Modifier*'
24
- # - 'DefMastership::ModifierFactory*'
25
- # - 'DefMastership::ParsingState*'
26
- # - 'DefMastership::RenameIncludedFilesModifier*'
27
- # - 'DefMastership::UpdateDefChecksumModifier*'
28
- # - 'DefMastership::UpdateDefModifier*'
29
- # - 'DefMastership::UpdateDefVersionModifier*'
14
+ - Defmastership*
15
+ ignore:
16
+ - Defmastership::Core*
17
+ # - Defmastership::BatchModifier*
18
+ # - Defmastership::Export::CSV::Formatter*
19
+ # - Defmastership::Export::CSV::BodyFormatter*
20
+ # - Defmastership::Export::CSV::HeaderFormatter*
21
+ # - Defmastership::Modifier::ChangeRef*
22
+ # - Defmastership::Definition*
23
+ # - Defmastership::DefinitionParser*
24
+ # - Defmastership::Document*
25
+ # - Defmastership::Factory*
26
+ # - Defmastership::Modifier::ModifierCommon*
27
+ # - Defmastership::Modifier::Factory*
28
+ # - Defmastership::Modifier::RenameIncludedFiles*
29
+ # - Defmastership::Modifier::UpdateDefChecksum*
30
+ # - Defmastership::Modifier::UpdateDef*
31
+ # - Defmastership::Modifier::UpdateDefVersion*
30
32
  # fail_fast: true
data/config/rubocop.yml CHANGED
@@ -13,6 +13,7 @@ require:
13
13
  - rubocop-performance
14
14
  - rubocop-rspec
15
15
  - rubocop-rake
16
+ - rubocop-yard
16
17
 
17
18
  AllCops:
18
19
  TargetRubyVersion: 2.7
@@ -34,10 +35,10 @@ Style/StringHashKeys :
34
35
  Enabled: true
35
36
  Exclude:
36
37
  - '*.gemspec'
37
- - 'spec/unit/def_mastership/batch_modifier_spec.rb'
38
- - 'spec/unit/def_mastership/update_def_checksum_modifier_spec.rb'
39
- - 'spec/unit/def_mastership/update_def_modifier_spec.rb'
40
- - 'spec/unit/def_mastership/update_def_version_modifier_spec.rb'
38
+ - 'spec/unit/defmastership/batch_modifier_spec.rb'
39
+ - 'spec/unit/defmastership/modifier/update_def_checksum_spec.rb'
40
+ - 'spec/unit/defmastership/modifier/update_def_spec.rb'
41
+ - 'spec/unit/defmastership/modifier/update_def_version_spec.rb'
41
42
 
42
43
  Style/MissingElse:
43
44
  EnforcedStyle: case
@@ -55,12 +56,6 @@ Security/Eval :
55
56
  Exclude:
56
57
  - 'Rakefile'
57
58
 
58
- Style/ConstantVisibility :
59
- Exclude:
60
- # there is one unique explicit constant visibility for all
61
- # constants
62
- - 'lib/defmastership/constants.rb'
63
-
64
59
  # rubocop-rspec options
65
60
  RSpec/MessageExpectation :
66
61
  Enabled: true
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  }
21
21
  spec.required_ruby_version = '>= 2.7'
22
22
  spec.name = 'defmastership'
23
- spec.version = DefMastership::VERSION
23
+ spec.version = Defmastership::VERSION
24
24
  spec.author = 'Jérôme Arbez-Gindre'
25
25
  spec.email = 'jeromearbezgindre@gmail.com'
26
26
  spec.licenses = ['MIT']
@@ -29,13 +29,13 @@ Gem::Specification.new do |spec|
29
29
  spec.summary = 'Handling of references and definitions with asciidoctor'
30
30
  spec.files = `git ls-files`.split("\n")
31
31
  spec.require_paths << 'lib'
32
- spec.extra_rdoc_files = ['README.rdoc', 'defmastership.rdoc']
33
- spec.rdoc_options << '--title defmastership' << '--main README.rdoc' << '-ri'
34
32
  spec.bindir = 'bin'
35
33
  spec.executables << 'defmastership'
36
34
  spec.add_dependency('aasm', '~> 5')
37
35
  spec.add_dependency('asciidoctor', '~> 2')
38
36
  spec.add_dependency('csv', '~> 3')
37
+ spec.add_dependency('defmastership-core', '>= 1.1.0')
39
38
  spec.add_dependency('git', '~> 1')
40
39
  spec.add_dependency('gli', '~> 2')
40
+ spec.add_dependency('ostruct', '~> 0')
41
41
  end
@@ -1,17 +1,35 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- module DefMastership
5
- # Change references from temporary to definitive with multiple RefChangers
4
+ module Defmastership
5
+ # Apply modications on a list of related asciidoc sources
6
6
  class BatchModifier
7
- attr_reader :config, :adoc_sources, :changes
8
-
7
+ # Stores the overall invocation configuration
8
+ # @return [YAML] configuration as eventualy modified by modifiers
9
+ attr_reader :config
10
+ # Stores the list of asciidoc files to modify and to save
11
+ # @return [Hash{String => String}] asciidoc sources as modified by modifiers
12
+ # * :key filename
13
+ # * :value file content
14
+ attr_reader :adoc_sources
15
+ # Provides the list of performed modifications
16
+ # @return [Array<Array<String>>] List of performed modifications
17
+ # (each line: [Modifier, Was, Becomes])
18
+ attr_reader :changes
19
+
20
+ # @param config [YAML] the overall modifications configurations
21
+ # @param adoc_sources [Hash{String => String}] asciidoctor files to be modified
22
+ # * Key: filename
23
+ # * Value: file content
9
24
  def initialize(config, adoc_sources)
10
25
  @config = config
11
26
  @adoc_sources = adoc_sources
12
27
  @changes = []
13
28
  end
14
29
 
30
+ # Apply modications on asciidoc sources of @adoc_sources
31
+ #
32
+ # @param modifs [Array<String>] The modifications to apply
15
33
  def apply(modifs)
16
34
  modifs.each do |modif|
17
35
  modifier = modifier_from(modif)
@@ -28,7 +46,7 @@ module DefMastership
28
46
  config_modif_sym = config[modif]
29
47
  raise(ArgumentError, "#{modif} is not a known modification") unless config_modif_sym
30
48
 
31
- ModifierFactory.from_config(config_modif_sym)
49
+ Modifier::Factory.from_config(config_modif_sym)
32
50
  end
33
51
 
34
52
  def collect_changes(modifier, modif)
@@ -4,7 +4,8 @@
4
4
  # adding a method to string to figure out if a string is commented or
5
5
  # not.
6
6
  class String
7
+ # @return [Boolean] true if the line is commented
7
8
  def commented?
8
- !!match(DefMastership::DMRegexp::SINGLE_LINE_COMMENT)
9
+ !!match(Defmastership::Core::DMRegexp::SINGLE_LINE_COMMENT)
9
10
  end
10
11
  end
@@ -3,8 +3,8 @@
3
3
 
4
4
  require 'digest'
5
5
 
6
- # Contains the content of a DefMastership definition
7
- module DefMastership
6
+ # Contains the content of a Defmastership definition
7
+ module Defmastership
8
8
  BUILD_FROM_MATCH = {
9
9
  type: ->(match) { match[:type] },
10
10
  reference: ->(match) { match[:reference] },
@@ -38,7 +38,7 @@ module DefMastership
38
38
 
39
39
  private_constant :DefinitionData
40
40
 
41
- # DefMastership definition: contains all data of a definition
41
+ # Defmastership definition: contains all data of a definition
42
42
  class Definition
43
43
  extend Forwardable
44
44
  def_delegators :@data,
@@ -52,6 +52,7 @@ module DefMastership
52
52
  :explicit_checksum,
53
53
  :explicit_version
54
54
 
55
+ # @param match [MatchData] the definition data from regepx match
55
56
  def initialize(match)
56
57
  @data = DefinitionData.new(
57
58
  *BUILD_FROM_MATCH.transform_values { |lamb| lamb.call(match) }
@@ -59,34 +60,53 @@ module DefMastership
59
60
  )
60
61
  end
61
62
 
63
+ # Add a line to the definition's value
64
+ #
65
+ # @param new_line [String] the new line
66
+ # @return [Definition] the definition itself
62
67
  def <<(new_line)
63
68
  lines << new_line
64
69
  self
65
70
  end
66
71
 
72
+ # Add a line to the definition's value
73
+ #
74
+ # @return [String] the complete value of the definition
67
75
  def value
68
76
  lines.join("\n")
69
77
  end
70
78
 
79
+ # @return [String] short representation (8 last characters) of the sha256 of the definition's value
71
80
  def sha256_short
72
81
  "~#{Digest::SHA2.hexdigest(value).chars.last(8).join}"
73
82
  end
74
83
 
84
+ # @return [String] the explicit checsum if wrong or nil
75
85
  def wrong_explicit_checksum
76
86
  explicit_checksum unless explicit_checksum.eql?(sha256_short)
77
87
  end
78
88
 
89
+ # Set an external ref list for a given reference type
90
+ #
91
+ # @param ref [String] the type of cross reference
92
+ # @param extrefs [String] the comma separated external references
79
93
  def add_eref(ref, extrefs)
80
94
  eref[ref] = extrefs.strip.split(/\s*,\s*/)
81
95
  end
82
96
 
97
+ # Set an internal ref
98
+ #
99
+ # @param ref [String] the internal reference
83
100
  def add_iref(ref)
84
101
  iref << ref
85
102
  end
86
103
 
104
+ # Set an attribute for a given key
105
+ #
106
+ # @param key [String] the attribute's key
107
+ # @param value [String] the attribute's value
87
108
  def set_attribute(key, value)
88
109
  attributes[key] = value
89
110
  end
90
111
  end
91
- public_constant :Definition
92
112
  end
@@ -3,8 +3,8 @@
3
3
 
4
4
  require('aasm')
5
5
 
6
- module DefMastership
7
- # DefMastership definition: contains all data of a definition
6
+ module Defmastership
7
+ # Defmastership definition: contains all data of a definition
8
8
  class DefinitionParser
9
9
  include AASM
10
10
 
@@ -2,10 +2,12 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require('asciidoctor')
5
+ require('defmastership/core/constants')
6
+ require('defmastership/core/parsing_state')
5
7
  require('defmastership/matching_line')
6
8
 
7
- # Contains the content of a DefMastership document: mainly definitions
8
- module DefMastership
9
+ # Contains the content of a Defmastership document: mainly definitions
10
+ module Defmastership
9
11
  # Class to host data of Document class
10
12
  DocumentData = Struct.new(
11
13
  :definitions,
@@ -37,9 +39,9 @@ module DefMastership
37
39
  definitions.last.add_eref(matching_line[:reference].to_sym, matching_line[:extrefs])
38
40
  },
39
41
  new_iref_def: lambda { |matching_line|
40
- self.iref = true
42
+ self.has_iref = true
41
43
  line = matching_line.line
42
- line.scan(DMRegexp::IREF_DEF) do |_|
44
+ line.scan(Core::DMRegexp::IREF_DEF) do |_|
43
45
  definitions.last.add_iref(Regexp.last_match[:intref])
44
46
  end
45
47
  },
@@ -54,7 +56,7 @@ module DefMastership
54
56
  },
55
57
  new_variable_use: lambda { |matching_line|
56
58
  line = matching_line.line
57
- line.scan(DMRegexp::VARIABLE_USE) do |_|
59
+ line.scan(Core::DMRegexp::VARIABLE_USE) do |_|
58
60
  varname = Regexp.last_match[:varname]
59
61
  value = variables[varname.to_sym]
60
62
 
@@ -75,36 +77,35 @@ module DefMastership
75
77
 
76
78
  def initialize
77
79
  @data = DocumentData.new([], Set.new, {}, false, {}, {})
78
- @parsing_state = ParsingState.new
80
+ @parsing_state = Core::ParsingState.new
79
81
  @definition_parser = DefinitionParser.new(self)
80
82
  end
81
83
 
82
- def parse(lines)
83
- lines.each do |line|
84
- if @parsing_state.enabled?(line)
85
- apply_filters(line)
86
- else
87
- generate_event(:new_line, MatchingLine.new(nil, line))
88
- end
89
- end
90
- end
91
-
84
+ # Parse asciidoc file after [Asciidoctor] preprocessing
85
+ #
86
+ # @param adoc_file [String] the file to parse
92
87
  def parse_file_with_preprocessor(adoc_file)
93
- parse(Asciidoctor.load_file(adoc_file, safe: :unsafe, parse: false).reader.read_lines)
88
+ do_parse(Asciidoctor.load_file(adoc_file, safe: :unsafe, parse: false).reader.read_lines)
94
89
  end
95
90
 
91
+ # @return [Boolean] true if the document has definitions with wrong explicit checksum
96
92
  def wrong_explicit_checksum?
97
93
  definitions.reduce(false) do |res, definition|
98
94
  res || !!definition.wrong_explicit_checksum
99
95
  end
100
96
  end
101
97
 
98
+ # @return [Boolean] true if the document has definitions with explicit versions
102
99
  def explicit_version?
103
100
  definitions.reduce(false) do |res, definition|
104
101
  res || !!definition.explicit_version
105
102
  end
106
103
  end
107
104
 
105
+ # Allow to add methods from parser actions
106
+ #
107
+ # @param method_name [Symbol] the name of the method
108
+ # @param args[Array<Object>] the arguments of the method
108
109
  def method_missing(method_name, *args)
109
110
  action = PARSER_ACTIONS[method_name]
110
111
  return instance_exec(*args, &action) if action
@@ -112,20 +113,36 @@ module DefMastership
112
113
  super
113
114
  end
114
115
 
116
+ # Allow to check if a parser action is available
117
+ #
118
+ # @param method_name [Symbol] the name of the method
119
+ # @param _args[Array<Object>] the arguments of the method
115
120
  # This method smells of :reek:UtilityFunction
116
121
  def respond_to_missing?(method_name, *_args)
117
122
  PARSER_ACTIONS.key?(method_name)
118
123
  end
119
124
 
125
+ # @param reference [String] the defintion from the reference
126
+ # @return [Definition] the defintion from the reference
120
127
  def ref_to_def(reference)
121
128
  definitions.find { |definition| definition.reference == reference }
122
129
  end
123
130
 
124
- def iref=(value)
131
+ private
132
+
133
+ def has_iref=(value)
125
134
  @data.iref = value
126
135
  end
127
136
 
128
- private
137
+ def do_parse(lines)
138
+ lines.each do |line|
139
+ if @parsing_state.enabled?(line)
140
+ apply_filters(line)
141
+ else
142
+ generate_event(:new_line, MatchingLine.new(nil, line))
143
+ end
144
+ end
145
+ end
129
146
 
130
147
  def apply_filters(line)
131
148
  Helper.reduce_filters_until_consumed(line) do |event, match, updated_line|
@@ -143,6 +160,9 @@ module DefMastership
143
160
 
144
161
  # Helper functions
145
162
  module Helper
163
+ # Helper function: apply all filters
164
+ #
165
+ # @param line [String] the line
146
166
  def self.reduce_filters_until_consumed(line)
147
167
  FILTERS.reduce(line) do |res, filter|
148
168
  next res unless line.match(filter.regexp)
@@ -0,0 +1,55 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/set_join_hack')
5
+
6
+ module Defmastership
7
+ module Export
8
+ # format CSV lines per definition
9
+ class BodyFormatter
10
+ # @param doc [Document] the document to export
11
+ # @param definition [String] the definition to export
12
+ def initialize(doc, definition)
13
+ @doc = doc
14
+ @definition = definition
15
+ end
16
+
17
+ # @return [Array<String>] list of always available columns values
18
+ def fixed
19
+ [@definition.type, @definition.reference, @definition.value, @definition.sha256_short]
20
+ end
21
+
22
+ # @return [Array<String>] Optional wrong_explicit_checksum column value
23
+ def wrong_explicit_checksum
24
+ wrong_explicit_checksum = @definition.wrong_explicit_checksum
25
+ wrong_explicit_checksum ? [wrong_explicit_checksum] : ['']
26
+ end
27
+
28
+ # @return [Array<String>] Optional version column value
29
+ def explicit_version
30
+ explicit_version = @definition.explicit_version
31
+ explicit_version ? [explicit_version] : ['']
32
+ end
33
+
34
+ # @return [Array<String>] Optional labels columns values
35
+ def labels
36
+ [@definition.labels.join("\n")]
37
+ end
38
+
39
+ # @return [Array<String>] Optional external refs columns values
40
+ def eref
41
+ @doc.eref.map { |key,| @definition.eref.fetch(key, []).join("\n") }
42
+ end
43
+
44
+ # @return [Array<String>] Optional internal refs column value
45
+ def iref
46
+ [@definition.iref.join("\n")]
47
+ end
48
+
49
+ # @return [Array<String>] Optional attributes columns values
50
+ def attributes
51
+ @doc.attributes.map { |key,| @definition.attributes.fetch(key, '') }
52
+ end
53
+ end
54
+ end
55
+ end