Module: Dapp::Helper::YAML
- Included in:
- Kube::Dapp::Dapp, Kube::Helm::Release, Kube::Kubernetes::Client, Kube::Kubernetes::Client, Kube::Kubernetes::Config
- Defined in:
- lib/dapp/helper/yaml.rb
Instance Method Summary collapse
- #yaml_load(string, hash: true) ⇒ Object
- #yaml_load_file(file_path, hash: true, default: {}) ⇒ Object
Instance Method Details
#yaml_load(string, hash: true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# 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. } end |
#yaml_load_file(file_path, hash: true, default: {}) ⇒ Object
4 5 6 7 8 9 |
# 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 |