Sha256: a58117497063debf41c243af8ccf6c8df9b45a7aec5e87265e3c56d95a5ac6fe

Contents?: true

Size: 1.64 KB

Versions: 9

Compression:

Stored size: 1.64 KB

Contents

  def dump(obj, name)
    File.write(name, obj)
  end

  def system!(str, show: false)
    log!(enter: __method__, args: [str], level: 2)
    STDERR.puts str if show
    rc = system(str)
    return rc if rc
    STDERR.puts "FAILED: #{str.inspect}"
    STDERR.puts "\ncaller = \n#{caller.join("\n  ")}\n"
    if defined?(RubyText)
      sleep 6
      RubyText.stop
      exit
    end
    return rc
  end

  def _get_data?(file)   # File need not exist
    if File.exist?(file)
      _get_data(file)
    else
      []
    end
  end

  def _get_data(file)
    lines = File.readlines(file)
    lines.reject! {|line| line[0] == "-" }  # allow rejection of lines
    lines = lines.map do |line|
      line.sub(/ *# .*$/, "")               # allow trailing comments
    end
    lines
  end

  def copy(src, dst)
    log!(enter: __method__, args: [src, dst], level: 2)
    cmd = "cp #{src} #{dst} 2>/dev/null"
    system!(cmd)
  end

  def copy!(src, dst)
    log!(enter: __method__, args: [src, dst], level: 2)
    cmd = "cp -r #{src} #{dst} 2>/dev/null"
    system!(cmd)
  end

  def create_dirs(*dirs)
    log!(enter: __method__, args: [*dirs], level: 3)
    dirs.each do |dir|
      dir = dir.to_s  # symbols allowed
      next if Dir.exist?(dir)
      cmd = "mkdir -p #{dir} >/dev/null"
      result = system!(cmd) 
      raise CantCreateDir(dir) unless result
    end
  end

  def interpolate(str, bind)
    log!(enter: __method__, args: [str, bind], level: 3)
    wrap = "<<-EOS\n#{str}\nEOS"
    eval wrap, bind
  end

  def error(err)
    log!(str: err, enter: __method__, args: [err], level: 2)
    str = "\n  Error: #{err}"
    puts str
    puts err.backtrace.join("\n")
  end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
runeblog-0.3.04 lib/lowlevel.rb
runeblog-0.3.03 lib/lowlevel.rb
runeblog-0.3.02 lib/lowlevel.rb
runeblog-0.3.01 lib/lowlevel.rb
runeblog-0.2.99 lib/lowlevel.rb
runeblog-0.2.98 lib/lowlevel.rb
runeblog-0.2.96 lib/lowlevel.rb
runeblog-0.2.95 lib/lowlevel.rb
runeblog-0.2.94 lib/lowlevel.rb