html-proofer 4.4.1 → 4.4.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: 4043366fa1c0d7aaa58fc0b577d25d2d0fba7e72afca2b43ae688e90c55dddef
4
- data.tar.gz: a93621d2169757d3665e5950e8c99d23a1b64cc9014fbc806a986fcdcb906e26
3
+ metadata.gz: e54554dcf4b21e6724cff760438b0a116c2871922f7ae0373b9d234d8202b2af
4
+ data.tar.gz: 4ab71e2407af3f65381bd48fec4ef9bba19a9849265884adfa7d6a7d7dd797ac
5
5
  SHA512:
6
- metadata.gz: 1636df520fa7d4035ca482eeafd0b5e059b0fc77a0219f340e7c47b8f2105c8dd107bf03e0d78ca582f5d7abef9d5853edae498a2133b75eab6f92b7e77b636f
7
- data.tar.gz: 5310df2250a5db3c8864b12ae01e49a0a2d043fc15f5bece45615cbad1d2b9100c899fa35902db5536b2be85908f9208ebfe65e31318cf6a6db47e945a745f17
6
+ metadata.gz: 228448293b92c6e5e5938201278f963fc2573c28869721d90671f31e84747cde91c6cfc5059da3b8404c4de874e67c319391b270de24e1df5afcf20062bda698
7
+ data.tar.gz: da4e98326f717141c3c433cd9afd651987a8a091f5a07cd2cf95e0b5034e0a33214bf63cc1f85b234999b2eb6047afb926437ca4ab56d0eb8f81e5eaaa4aab2f
@@ -49,6 +49,8 @@ module HTMLProofer
49
49
 
50
50
  class << self
51
51
  def generate_defaults(opts)
52
+ validate_options(default_options, opts)
53
+
52
54
  options = PROOFER_DEFAULTS.merge(opts)
53
55
 
54
56
  options[:typhoeus] = HTMLProofer::Configuration::TYPHOEUS_DEFAULTS.merge(opts[:typhoeus] || {})
@@ -86,6 +88,24 @@ module HTMLProofer
86
88
  raise ArgumentError, "Option '#{option_name} did not contain valid JSON."
87
89
  end
88
90
  end
91
+
92
+ private
93
+
94
+ def default_options
95
+ PROOFER_DEFAULTS.merge(typhoeus: TYPHOEUS_DEFAULTS).merge(hydra: HYDRA_DEFAULTS).merge(parallel: PARALLEL_DEFAULTS)
96
+ end
97
+
98
+ def validate_options(defaults, options)
99
+ defaults.each do |key, default_value|
100
+ next unless options.key?(key)
101
+
102
+ value = options[key]
103
+ raise TypeError, "Invalid value for '#{key}': '#{value}'. Expected #{default_value.class}." unless value.is_a?(default_value.class)
104
+
105
+ # Iterate over nested hashes
106
+ validate_options(default_value, value) if default_value.is_a?(Hash)
107
+ end
108
+ end
89
109
  end
90
110
  end
91
111
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTMLProofer
4
- VERSION = "4.4.1"
4
+ VERSION = "4.4.2"
5
5
  end
data/lib/html_proofer.rb CHANGED
@@ -25,7 +25,7 @@ module HTMLProofer
25
25
  raise ArgumentError unless file.is_a?(String)
26
26
  raise ArgumentError, "#{file} does not exist" unless File.exist?(file)
27
27
 
28
- options[:type] = :file
28
+ options = prepare_options(options, :file)
29
29
  HTMLProofer::Runner.new(file, options)
30
30
  end
31
31
 
@@ -33,14 +33,14 @@ module HTMLProofer
33
33
  raise ArgumentError unless directory.is_a?(String)
34
34
  raise ArgumentError, "#{directory} does not exist" unless Dir.exist?(directory)
35
35
 
36
- options[:type] = :directory
36
+ options = prepare_options(options, :directory)
37
37
  HTMLProofer::Runner.new([directory], options)
38
38
  end
39
39
 
40
40
  def check_directories(directories, options = {})
41
41
  raise ArgumentError unless directories.is_a?(Array)
42
42
 
43
- options[:type] = :directory
43
+ options = prepare_options(options, :directory)
44
44
  directories.each do |directory|
45
45
  raise ArgumentError, "#{directory} does not exist" unless Dir.exist?(directory)
46
46
  end
@@ -50,9 +50,20 @@ module HTMLProofer
50
50
  def check_links(links, options = {})
51
51
  raise ArgumentError unless links.is_a?(Array)
52
52
 
53
- options[:type] = :links
53
+ options = prepare_options(options, :links)
54
54
  HTMLProofer::Runner.new(links, options)
55
55
  end
56
+
57
+ private
58
+
59
+ def prepare_options(options, type)
60
+ options = {} if options.nil?
61
+
62
+ raise ArgumentError, "Options must be a Hash" unless options.is_a?(Hash)
63
+
64
+ options[:type] = type
65
+ options
66
+ end
56
67
  end
57
68
  end
58
69
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-proofer
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-25 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable