Module: RSpec::Chef::JSONSupport

Included in:
DefineRecipeGroup
Defined in:
lib/rspec-chef/json_support.rb

Instance Method Summary collapse

Instance Method Details

#json(data) ⇒ Object

Transform JSON data into a Hash If data is the path to a file it reads the file and transform its content.



6
7
8
9
10
11
12
13
14
# File 'lib/rspec-chef/json_support.rb', line 6

def json(data)
  if data.is_a?(Hash)
    data
  elsif File.file?(data)
    ::Chef::JSONCompat.from_json(File.read(data)) rescue {}
  else
    ::Chef::JSONCompat.from_json(data) rescue {}
  end
end