Class: PDK::Validate::Metadata::MetadataSyntaxValidator
Instance Attribute Summary
Attributes inherited from Validator
#context, #options, #prepared
Instance Method Summary
collapse
#prepare_invoke!
#allow_empty_targets?, #fnmatch?, #ignore_dotfiles?, #invoke_style, #parse_targets, #pattern_ignore, #prepare_invoke!, #process_invalid, #process_skipped, #spinner, #valid_in_context?
Methods inherited from Validator
#initialize, #prepare_invoke!, #spinner, #spinners_enabled?, #start_spinner, #stop_spinner, #valid_in_context?
Instance Method Details
#before_validation ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/pdk/validate/metadata/metadata_syntax_validator.rb', line 25
def before_validation
require 'json/pure'
JSON.parser = JSON::Pure::Parser
end
|
#invoke(report) ⇒ Object
19
20
21
22
23
|
# File 'lib/pdk/validate/metadata/metadata_syntax_validator.rb', line 19
def invoke(report)
super
ensure
JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
end
|
#name ⇒ Object
7
8
9
|
# File 'lib/pdk/validate/metadata/metadata_syntax_validator.rb', line 7
def name
'metadata-syntax'
end
|
#pattern ⇒ Object
11
12
13
|
# File 'lib/pdk/validate/metadata/metadata_syntax_validator.rb', line 11
def pattern
contextual_pattern(['metadata.json', 'tasks/*.json'])
end
|
#spinner_text ⇒ Object
15
16
17
|
# File 'lib/pdk/validate/metadata/metadata_syntax_validator.rb', line 15
def spinner_text
format('Checking metadata syntax (%{patterns}).', patterns: pattern.join(' '))
end
|
#validate_target(report, target) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/pdk/validate/metadata/metadata_syntax_validator.rb', line 34
def validate_target(report, target)
unless PDK::Util::Filesystem.readable?(target)
report.add_event(
file: target,
source: name,
state: :failure,
severity: 'error',
message: 'Could not be read.'
)
return 1
end
begin
JSON.parse(PDK::Util::Filesystem.read_file(target))
report.add_event(
file: target,
source: name,
state: :passed,
severity: 'ok'
)
0
rescue JSON::ParserError => e
sane_message = e.message.dump[/\A"(.+?)!?"\Z/, 1]
report.add_event(
file: target,
source: name,
state: :failure,
severity: 'error',
message: sane_message
)
1
end
end
|