class JsonUpdater::JsonValidator
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/json_updater/json_validator.rb, line 7 def initialize(path) @path = path end
Public Instance Methods
messages()
click to toggle source
# File lib/json_updater/json_validator.rb, line 15 def messages return "#{path} - file does't exist" unless file_exist? return "#{path} - json file doesn't valid" unless json_valid? end
valid?()
click to toggle source
# File lib/json_updater/json_validator.rb, line 11 def valid? file_exist? && json_valid? end
Private Instance Methods
file_exist?()
click to toggle source
# File lib/json_updater/json_validator.rb, line 22 def file_exist? File.exist? path end
json_valid?()
click to toggle source
# File lib/json_updater/json_validator.rb, line 26 def json_valid? file = File.open(path).read JSON.parse(file) true rescue JSON::ParserError => _e false end