distincter2 1.3.1 → 1.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b8d1d5aa62302ef718c566a9053311075f4999fc1e8509c1e2d93e788f85a87
4
- data.tar.gz: 66ebec72784df7a866f179c730f354120db1e227911655a8ee11ce509947adb5
3
+ metadata.gz: e7356757437f888b0a6ab4054086150075337e10a56bd32c970bd2bd1e6c5687
4
+ data.tar.gz: 385dddc273aab58dad6002c533feeb72002f886fdb82ef45ce35f12a8d7179f3
5
5
  SHA512:
6
- metadata.gz: 81680f8b162f0851527be19be9a8018ebf34a9a613aab8f7451a9035ba3e8b1146303054810dff9724638ab3bd871965e27a2c030949c85804a2a477e0e6f4f4
7
- data.tar.gz: 9c5898feafe48a5111c47bdbe99907c2b36eba081ffcc2d89f9e70cdaa9cbc542828f76f10cf6f64ba7d7dc68acb6a44a9793f2f4b0e324b11277b7e4c25fa1d
6
+ metadata.gz: 20c5b2ea990ec92ead8e5b0808ab0ce1cb75f2dc3bc0075c3945e1f40e5cfb5cc5fc17cfbe13368d34817841455d81c799103a615746665a0fa472c3759fa867
7
+ data.tar.gz: a8d452f076387b8087486e251adfdf9d43033213da477f8ff3ddacfceee6c212d70f3717ecb40369a9a5e0d3e25eeee62738788c6be162a00473b2c80a4f1e5e
data/README.md CHANGED
@@ -47,6 +47,27 @@ BOOKS.md
47
47
  DONE.md
48
48
  ```
49
49
 
50
+ ## How to contribute
51
+
52
+ ### Documentation
53
+
54
+ Just run:
55
+
56
+ ```shell
57
+ $ rdoc
58
+ ```
59
+
60
+ ### Contribution
61
+
62
+ Read [Commit Convention](./COMMIT_CONVENTION.md). Make sure your build is green before you contribute your pull request.
63
+ Then:
64
+
65
+ ```shell
66
+ $ bundle exec rake
67
+ ```
68
+
69
+ If you don't see any error messages, submit your pull request.
70
+
50
71
  ## Contributors
51
72
 
52
73
  * [@fartem](https://github.com/fartem) as Artem Fomchenkov
@@ -1,26 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Distincter2
4
- # distincter2 checker.
5
- # Handles a file and operate them.
4
+ # Class to check for duplicate lines in markdown files
6
5
  class D2Checker
7
- # @param {D2Config} config
8
- # @param {Boolean} mute
6
+ # Initialize the D2Checker with a configuration object and an optional mute flag
7
+ #
8
+ # @param config [Object] The configuration object containing settings for the checker
9
+ # @param mute [Boolean] A flag indicating whether to mute the output of duplicate lines (default: false)
9
10
  def initialize(config, mute: false)
10
11
  @config = config
11
12
  @mute = mute
12
13
  end
13
14
 
14
- # @param {String} path
15
+ # Check for duplicate lines in markdown files within a given directory
16
+ #
17
+ # @param path [String] The path to the directory to check
18
+ # @return [Array] An array of duplicate lines found in the markdown files
15
19
  def check(path)
16
20
  duplicates = analyze_dir(path)
17
21
 
18
22
  exit(duplicates.empty? ? 0 : 1)
19
23
  end
20
24
 
21
- # @param {String} path
22
- # @return {String[]}
23
- # rubocop:disable Metrics/MethodLength
25
+ # Recursively analyze a directory for duplicate lines in markdown files
26
+ #
27
+ # @param path [String] The path to the directory to analyze
28
+ # @return [Array] An array of duplicate lines found in the markdown files
24
29
  def analyze_dir(path)
25
30
  duplicates = []
26
31
  ::Dir.foreach(path).each do |entry|
@@ -45,18 +50,20 @@ module Distincter2
45
50
  duplicates
46
51
  end
47
52
 
48
- # rubocop:enable Metrics/MethodLength
49
-
50
- # @param {String} entry
53
+ # Check if a file can be analyzed based on the configuration settings
54
+ #
55
+ # @param entry [String] The name of the file to check
56
+ # @return [Boolean] True if the file can be analyzed, false otherwise
51
57
  def can_analyze(entry)
52
58
  return false unless @config.version == 'v1'
53
59
 
54
60
  @config.exclude_paths.none?(entry)
55
61
  end
56
62
 
57
- # @param {String} path
58
- # @return {String[]}
59
- # rubocop:disable Metrics/MethodLength
63
+ # Analyze a markdown file for duplicate lines
64
+ #
65
+ # @param path [String] The path to the markdown file to analyze
66
+ # @return [Array] An array of duplicate lines found in the markdown file
60
67
  def analyze_file(path)
61
68
  lines = []
62
69
  ::File.open(path, 'r') do |file|
@@ -75,7 +82,5 @@ module Distincter2
75
82
 
76
83
  duplicates
77
84
  end
78
-
79
- # rubocop:enable Metrics/MethodLength
80
85
  end
81
86
  end
@@ -3,51 +3,71 @@
3
3
  require 'set'
4
4
 
5
5
  module Distincter2
6
- # Distincter2 config.
6
+ # Class representing the configuration for Distincter2.
7
7
  class D2Config
8
- # @param {String[]} exclude_paths
9
- # @param {String} version
8
+ # Initializes a new instance of D2Config.
9
+ #
10
+ # @param exclude_paths [Array<String>] An array of paths to be excluded.
11
+ # @param version [String] The version of the configuration. Default is 'v1'.
10
12
  def initialize(exclude_paths, version = 'v1')
11
13
  @exclude_paths = exclude_paths.to_set
12
14
  @version = version
13
15
  end
14
16
 
15
- attr_accessor :exclude_paths, :version
17
+ # Accessor for the exclude_paths attribute.
18
+ #
19
+ # @return [Set<String>] The set of paths to be excluded.
20
+ attr_accessor :exclude_paths
21
+
22
+ # Accessor for the version attribute.
23
+ #
24
+ # @return [String] The version of the configuration.
25
+ attr_accessor :version
16
26
  end
17
27
 
18
- # D2Config with empty arguments.
19
- class D2ConfigEmpty < ::Distincter2::D2Config
28
+ # Class representing an empty configuration for Distincter2.
29
+ # This class inherits from D2Config and initializes with an empty array of exclude_paths.
30
+ class D2EmptyConfig < ::Distincter2::D2Config
20
31
  # Constructor without paths.
32
+ #
33
+ # @return [void]
21
34
  def initialize
35
+ # Calls the parent class's initialize method with an empty array of exclude_paths.
22
36
  super([])
23
37
  end
24
38
  end
25
39
 
26
- # D2Config parser.
40
+ # Class representing a parser for Distincter2 configuration files.
27
41
  class D2ConfigParser
28
- # @param {String} config_path
42
+ # Initializes a new instance of D2ConfigParser.
43
+ #
44
+ # @param config_path [String] The path to the configuration file.
29
45
  def initialize(config_path)
30
46
  @config_path = config_path
31
47
  end
32
48
 
33
- # @return {D2Config}
34
- # rubocop:disable Metrics/MethodLength
49
+ # Parses the configuration file and returns a D2Config object.
50
+ #
51
+ # @return [Distincter2::D2Config] A D2Config object representing the parsed configuration.
35
52
  def parse
36
53
  exclude_paths = []
37
54
  version = 'v1'
55
+
56
+ # Open the configuration file and read its lines.
38
57
  ::File.open(@config_path, 'r') do |file|
39
58
  file.readlines.each do |line|
40
59
  l = line.strip
41
60
 
42
- next if l == 'v1'
43
-
44
- next if l.empty?
61
+ # Skip lines that contain the version number or are empty.
62
+ next if l == 'v1' || l.empty?
45
63
 
64
+ # Add the non-empty, non-version lines to the exclude_paths array.
46
65
  exclude_paths << l
47
66
  end
48
67
  end
68
+
69
+ # Create a new D2Config object with the parsed exclude_paths and version.
49
70
  ::Distincter2::D2Config.new(exclude_paths, version)
50
71
  end
51
- # rubocop:enable Metrics/MethodLength
52
72
  end
53
73
  end
data/lib/distincter2.rb CHANGED
@@ -5,18 +5,35 @@ require_relative './distincter2/config'
5
5
 
6
6
  module Distincter2
7
7
  # distincter2 runner. Just an entrypoint.
8
+ # This class represents the main entry point for the Distincter2 runner.
8
9
  class Distincter2
10
+ # This method starts the validation process for a given project path.
9
11
  #
10
- # You need a project path to run validation.
12
+ # @param path [String] The path to the project directory.
13
+ # @return [void]
14
+ #
15
+ # @example
16
+ # # Create an instance of Distincter2
17
+ # distincter = Distincter2.new
18
+ #
19
+ # # Start the validation process for a project located at '/path/to/project'
20
+ # distincter.start('/path/to/project')
11
21
  def start(path)
22
+ # Construct the path to the distincter2_config.d2c file
12
23
  config_path = "#{path}/distincter2_config.d2c"
24
+
25
+ # Create a new D2Checker instance with the appropriate configuration
13
26
  checker = ::Distincter2::D2Checker.new(
14
27
  if ::File.exist?(config_path)
28
+ # If the config file exists, parse it and use the parsed configuration
15
29
  ::Distincter2::D2ConfigParser.new(config_path).parse
16
30
  else
17
- ::Distincter2::D2ConfigEmpty.new
31
+ # If the config file does not exist, use an empty configuration
32
+ ::Distincter2::D2EmptyConfig.new
18
33
  end
19
34
  )
35
+
36
+ # Run the validation process using the checker
20
37
  checker.check(path)
21
38
  end
22
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distincter2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Fomchenkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2024-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize