Sha256: ab49f6acd406b377bcca4f117f0f7d7484b19d2930cd45654a18e962fe542756

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require "yaml"

module Ykxutils
  module_function

  def yaml_load_file_aliases(yaml_file_path, use_aliases: true)
    begin
      use_aliases ? YAML.load_file(yaml_file_path, aliases: true) : YAML.load_file(yaml_file_path)
      value = 0
    rescue ArgumentError
      # puts e.message
      value = 1
    rescue StandardError
      # puts e.message
      value = 2
    end
    value
  end

  def yaml_load_file_compati(yaml_file_path)
    setting = yaml_load_file_aliases(yaml_file_path, use_aliases: true)
    setting = yaml_load_file_aliases(yaml_file_path, use_aliases: false) if setting.nil?
    setting
  end

  def yaml_load_aliases(content, use_aliases: true)
    begin
      use_aliases ? YAML.safe_load(content, aliases: true) : YAML.safe_load(content)
      value = 0
    rescue ArgumentError
      # puts e.message
      value = 1
    rescue StandardError
      # puts e.message
      value = 2
    end
    value
  end

  def yaml_load_compati(content)
    setting = yaml_load_aliases(content, use_aliases: true)
    setting = yaml_load_aliases(content, use_aliases: false) if setting.nil?
    setting
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ykxutils-0.1.8 lib/ykxutils/yamlx.rb