module MistralClient::Mixins::Definable

Public Instance Methods

parse_definition(definition) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/mistral_client/mixins/definable.rb, line 5
def parse_definition(definition)
  return YAML.dump(definition) if definition.is_a?(Hash) || definition.is_a?(Array)

  definition = File.read(definition) if File.exist?(definition)
  # Called outside the if/else to validate the YAML.
  parsed = YAML.safe_load(definition, [], [], true)
  if defined? massage_definition
    massage_definition(parsed)
  else
    definition
  end
rescue Psych::SyntaxError
  raise ConfigurationError,
        'Only filenames or raw or parsed strings of YAML are supported.'
end