Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#aargh(message, return_value = nil) ⇒ Object

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



6
7
8
9
10
# 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) ⇒ Object



12
13
14
15
16
17
18
# 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) ⇒ Object



20
21
22
23
24
25
26
# 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