Sha256: 6da57421719034a8f628a49561e5703238665397c266c8a9e9dfd485f4b7fc92

Contents?: true

Size: 1.17 KB

Versions: 34

Compression:

Stored size: 1.17 KB

Contents

require "tmpdir"
require "shellwords"

ARGV.each do |path|
  puts "~~~~~~~ Checking #{path} ~~~~~~"
  content = File.read(path)

  snippets = []
  lines = []
  content.lines.each.with_index do |line, index|
    case line
    when /run-start:/
      lines = [[line, index+1]]
    when /run-end/
      lines << [line, index+1]
      snippets << lines
      lines = []
    else
      lines << [line, index+1]
    end
  end

  snippets.each do |lines|
    puts ">>> Code detected: "
    hd, _, *code_lines, _, _ = lines

    head = hd[0]
    head.gsub!(/^<!-- +/, "").gsub!(/ +-->$/, "")
    _,name,command = head.split(/:/)

    puts "# command=#{Shellwords.split(command).inspect}"
    puts "# name=#{name}"
    puts code_lines.map {|line, i| "#{"%4d" % i}  #{line}" }.join

    code = code_lines.map(&:first).join

    puts ">>> Running..."
    Dir.mktmpdir do |dir|
      File.write(File.join(dir, name), code)
      pid = spawn({ "BUNDLE_GEMFILE" => File.join(__dir__, "../Gemfile") },
                  *Shellwords.split(command),
                  chdir: dir)

      _, status = Process.waitpid2(pid)

      status.success? or raise "Failed to execute code: #{code_lines.join}"
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
rbs-1.2.0 bin/run_in_md.rb
rbs-1.1.1 bin/run_in_md.rb
rbs-1.1.0 bin/run_in_md.rb
rbs-1.0.6 bin/run_in_md.rb
rbs-1.0.5 bin/run_in_md.rb
rbs-1.0.4 bin/run_in_md.rb
rbs-1.0.3 bin/run_in_md.rb
rbs-1.0.2 bin/run_in_md.rb
rbs-1.0.1 bin/run_in_md.rb
rbs-1.0.0 bin/run_in_md.rb
rbs-1.0.0.pre2 bin/run_in_md.rb
rbs-1.0.0.pre bin/run_in_md.rb
rbs-0.20.1 bin/run_in_md.rb
rbs-0.20.0 bin/run_in_md.rb
rbs-0.19.0 bin/run_in_md.rb
rbs-0.18.1 bin/run_in_md.rb
rbs-0.18.0 bin/run_in_md.rb
rbs-0.17.0 bin/run_in_md.rb
rbs-0.16.0 bin/run_in_md.rb
rbs-0.15.0 bin/run_in_md.rb