Class: Chef::Resource::File::Verification::Json

Inherits:
Chef::Resource::File::Verification show all
Defined in:
lib/chef/resource/file/verification/json.rb

Overview

Extends File verification to provide Json verification

Example: file ‘foo.json’ do

content '{"foo": "bar"}'
verify :json

end

Instance Attribute Summary

Attributes inherited from Chef::Resource::File::Verification

#output

Instance Method Summary collapse

Methods inherited from Chef::Resource::File::Verification

#initialize, #logger, lookup, provides, provides?, #to_s, #verify_block, #verify_command, #verify_registered_verification

Methods included from Mixin::DescendantsTracker

#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited

Constructor Details

This class inherits a constructor from Chef::Resource::File::Verification

Instance Method Details

#verify(path, opts = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/chef/resource/file/verification/json.rb', line 39

def verify(path, opts = {})
  Chef::JSONCompat.parse(IO.read(path))
  true
rescue Chef::Exceptions::JSON::ParseError => e
  Chef::Log.error("Json syntax verify failed with : #{e.message}")
  false
end