Skip to content

Commit 2534951

Browse files
authored
Merge pull request #442 from DannyBen/add/libraries-yml-validation
Validate libraries.yml
2 parents f5d2850 + b52dc92 commit 2534951

25 files changed

+140
-9
lines changed

examples/render-mandoc/docs/download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
. ftr VB CB
1515
. ftr VBI CBI
1616
.\}
17-
.TH "download" "1" "September 2023" "Version 0.1.0" "Sample application"
17+
.TH "download" "1" "October 2023" "Version 0.1.0" "Sample application"
1818
.hy
1919
.SH NAME
2020
.PP

examples/render-mandoc/docs/download.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% download(1) Version 0.1.0 | Sample application
22
% Lana Lang
3-
% September 2023
3+
% October 2023
44

55
NAME
66
==================================================

lib/bashly.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Bashly
1515
autoload :ConfigValidator, 'bashly/config_validator'
1616
autoload :Library, 'bashly/library'
1717
autoload :LibrarySource, 'bashly/library_source'
18+
autoload :LibrarySourceConfig, 'bashly/library_source_config'
1819
autoload :MessageStrings, 'bashly/message_strings'
1920
autoload :RenderContext, 'bashly/render_context'
2021
autoload :RenderSource, 'bashly/render_source'

lib/bashly/library_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def git?
1515
end
1616

1717
def config
18-
@config ||= YAML.load_file config_path
18+
@config ||= LibrarySourceConfig.new(config_path).validated_data
1919
end
2020

2121
def libraries

lib/bashly/library_source_config.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Bashly
2+
class LibrarySourceConfig
3+
include ValidationHelpers
4+
5+
attr_reader :path
6+
7+
def initialize(path)
8+
@path = path
9+
end
10+
11+
def data
12+
@data ||= YAML.load_file path
13+
end
14+
15+
def validated_data
16+
validate
17+
data
18+
end
19+
20+
def validate
21+
assert_root path, data
22+
end
23+
24+
private
25+
26+
def assert_root(path, value)
27+
assert_hash path, value
28+
data.each { |id, spec| assert_lib "[#{path}] #{id}", spec }
29+
end
30+
31+
def assert_lib(key, value)
32+
assert_string "#{key}.help", value['help']
33+
34+
assert_optional_string "#{key}.usage", value['usage']
35+
assert_optional_string "#{key}.handler", value['handler']
36+
assert_optional_string "#{key}.post_install_message", value['post_install_message']
37+
38+
return if value['handler']
39+
40+
assert_array "#{key}.files", value['files'], of: :filespec
41+
end
42+
43+
def assert_filespec(key, value)
44+
assert_string "#{key}.source", value['source']
45+
assert_string "#{key}.target", value['target']
46+
end
47+
end
48+
end

spec/approvals/examples/render-mandoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ ISSUE TRACKER
4444
AUTHORS
4545
Lana Lang.
4646

47-
Version 0.1.0 September 2023 download(1)
47+
Version 0.1.0 October 2023 download(1)

spec/approvals/libraries/render/mandoc/render-1-download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ EXAMPLES
2929
download example.com ./output -f
3030

3131

32-
Version 0.1.0 MONTH YEAR download(1)
32+
Version 0.1.0 MONTH YEAR download(1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/files_array.yml] database.files must be an array>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/files_source.yml] database.files[0].source must be a string>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: [spec/fixtures/libraries/errors/files_target.yml] database.files[0].target must be a string>

0 commit comments

Comments
 (0)