Module: Fontist::Helpers

Defined in:
lib/fontist/helpers.rb

Class Method Summary collapse

Class Method Details

.parse_to_object(data) ⇒ Object



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

def self.parse_to_object(data)
  JSON.parse(data.to_json, object_class: OpenStruct)
end

.run(command) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fontist/helpers.rb', line 7

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



19
20
21
22
23
24
25
26
# File 'lib/fontist/helpers.rb', line 19

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