Class: JsonLint::Linter
- Inherits:
-
Object
show all
- Defined in:
- lib/jsonlint/linter.rb
Defined Under Namespace
Classes: KeyOverlapDetector
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Linter
Returns a new instance of Linter.
10
11
12
|
# File 'lib/jsonlint/linter.rb', line 10
def initialize
@errors = {}
end
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
8
9
10
|
# File 'lib/jsonlint/linter.rb', line 8
def errors
@errors
end
|
Instance Method Details
#check(path) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/jsonlint/linter.rb', line 18
def check(path)
fail FileNotFoundError, "#{path}: no such file" unless File.exist?(path)
valid = false
File.open(path, 'r') do |f|
error_array = []
valid = check_data(f.read, error_array)
errors[path] = error_array unless error_array.empty?
end
valid
end
|
#check_all(*files_to_check) ⇒ Object
14
15
16
|
# File 'lib/jsonlint/linter.rb', line 14
def check_all(*files_to_check)
files_to_check.flatten.each { |f| check(f) }
end
|
#check_stream(io_stream) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/jsonlint/linter.rb', line 31
def check_stream(io_stream)
json_data = io_stream.read
error_array = []
valid = check_data(json_data, error_array)
errors[''] = error_array unless error_array.empty?
valid
end
|
#display_errors ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/jsonlint/linter.rb', line 45
def display_errors
errors.each do |path, errors|
puts path
errors.each do |err|
puts " #{err}"
end
end
end
|
#errors? ⇒ Boolean
41
42
43
|
# File 'lib/jsonlint/linter.rb', line 41
def errors?
!errors.empty?
end
|