Module: Fontist::Helpers

Defined in:
lib/fontist/helpers.rb

Class Method Summary collapse

Class Method Details

.run(command) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fontist/helpers.rb', line 10

def self.run(command)
  Fontist.ui.debug("Run `#{command}`")

  result = `#{command}`
  unless $CHILD_STATUS.to_i.zero?
    raise Errors::BinaryCallError,
          "Failed to run #{command}, status: #{$CHILD_STATUS}"
  end

  result
end

.silence_stream(stream) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/fontist/helpers.rb', line 22

def self.silence_stream(stream)
  old_stream = stream.dup
  stream.reopen(RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ ? "NUL:" : "/dev/null") # rubocop:disable Performance/RegexpMatch, Metrics/LineLength
  stream.sync = true
  yield
ensure
  stream.reopen(old_stream)
end

.url_object(request) ⇒ Object



3
4
5
6
7
8
# File 'lib/fontist/helpers.rb', line 3

def self.url_object(request)
  return request unless request.include?("\"url\"")

  obj = JSON.parse(request.gsub("=>", ":"))
  Struct.new(:url, :headers).new(obj["url"], obj["headers"])
end