module Dapp::Helper::YAML

Public Instance Methods

yaml_load(string, hash: true) click to toggle source
# File lib/dapp/helper/yaml.rb, line 11
def yaml_load(string, hash: true)
  ::YAML::load(string).tap do |res|
    if hash && !res.is_a?(Hash)
      raise ::Dapp::Error::Dapp,
            code: :yaml_incorrect,
            data: { message: "unexpected yaml data \n>>> START YAML\n#{string.strip}\n>>> END YAML\n" }
    end
  end
rescue Psych::SyntaxError => e
  raise ::Dapp::Error::Dapp, code: :yaml_incorrect, data: { message: e.message }
end
yaml_load_file(file_path, hash: true, default: {}) click to toggle source
# File lib/dapp/helper/yaml.rb, line 4
def yaml_load_file(file_path, hash: true, default: {})
  return default if (context = File.read(file_path).strip).empty?
  yaml_load(context, hash: hash)
rescue ::Dapp::Error::Dapp => e
  raise ::Dapp::Error::Dapp, code: :yaml_file_incorrect, data: { file: file_path, message: e.net_status[:data][:message] }
end