class Object

Public Instance Methods

aargh(message, return_value = nil) click to toggle source

Copyright © 2021 Ismo Kärkkäinen Licensed under Universal Permissive License. See LICENSE.txt.

# File lib/common.rb, line 6
def aargh(message, return_value = nil)
  message = (message.map &(:to_s)).join("\n") if message.is_a? Array
  $stderr.puts message
  return_value
end
load_source(input) click to toggle source
# File lib/common.rb, line 12
def load_source(input)
  YAML.safe_load(input.nil? ? $stdin : File.read(input))
rescue Errno::ENOENT
  aargh "Could not load #{input || 'stdin'}"
rescue StandardError => e
  aargh "#{e}\nFailed to read #{input || 'stdin'}"
end
load_source_hash(input) click to toggle source
# File lib/common.rb, line 20
def load_source_hash(input)
  src = load_source(input)
  unless src.nil?
    return aargh('Input is not a mapping.') unless src.is_a? Hash
  end
  src
end