Sha256: d47fdb767094d2573935cd575dc3ff36999e8cef5d94ee2a7bf74c5650c170fc

Contents?: true

Size: 528 Bytes

Versions: 2

Compression:

Stored size: 528 Bytes

Contents

class NodeJs
  NODEJS_EXEC = 'node'

  def self.installed?
    unless NodeJs.path == ''
      `#{NodeJs.path} -v`
      $? == 0
    else
      false
    end
  end

  def self.path
    @path ||= `which #{NODEJS_EXEC}`.gsub("\n", "")
  end

  def self.execute(node_cmd, stdin = nil)
    cmd_dir = File.dirname(node_cmd)
    Dir.chdir(cmd_dir)

    shell_out = ""

    IO.popen "#{NodeJs.path} #{node_cmd}", 'r+' do |io|
      io.puts(stdin) if stdin
      io.close_write
      shell_out = io.read
    end

    shell_out
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gson_parser-0.1.1 lib/node_js.rb
gson_parser-0.1.0 lib/node_js.rb