class Object

Public Instance Methods

get_lang(lang) click to toggle source
# File lib/asciibuild/extensions.rb, line 34
def get_lang lang
  case lang
  when 'pyspark'
    'python'
  when 'spark-shell'
    'scala'
  when 'docker-compose'
    'yaml'
  else
    lang
  end
end
include_section?(parent, attrs) click to toggle source
# File lib/asciibuild/extensions.rb, line 6
def include_section? parent, attrs
  if parent.document.attributes["error"]
    return false
  elsif parent.title == "Before All" or parent.title == "After All"
    return true
  end

  sections = if parent.document.attributes["sections"]
    parent.document.attributes["sections"].split(/,[ ]*/)
  else
    []
  end

  deps = []

  incl_sect = sections.empty?
  sections.each do |s|
    if not incl_sect
      if Regexp.new(s) =~ parent.title
        incl_sect = true
        deps << "Before " + parent.title << "After " + parent.title
      end
    end
  end

  incl_sect or deps.include?(parent.title)
end
normalize(parent, attrs, lines) click to toggle source
# File lib/asciibuild/extensions.rb, line 56
def normalize parent, attrs, lines
  redact = parent.document.attributes['redact']
  patts = if redact
    if redact.class == Array
      redact
    else
      [redact]
    end
  else
    []
  end

  new_lines = []
  lines.each do |l|
    patts.each do |p|
      l = l.gsub(Regexp.new(p), "[****]")
    end
    new_lines << l.gsub(/\e\[([;\d]+)?m/, '') # Sneak in ANSI color stripping here as well
  end
  new_lines
end
wait_for_container(cid) click to toggle source
# File lib/asciibuild/extensions.rb, line 78
def wait_for_container cid
  cmd = "docker inspect -f {{.State.Running}} %s" % cid
  cout, cerr, cstatus = Open3.capture3(cmd)
  until cstatus != 0 or cout.chomp == "true" do
    sleep 0.1
    cout, cerr, cstatus = Open3.capture3(cmd)
  end
end
write_file(attrs, default_name, body) click to toggle source
# File lib/asciibuild/extensions.rb, line 47
def write_file attrs, default_name, body
  name = attrs['file'] ||= default_name
  mode = if attrs['overwrite'] == 'false' then File::WRONLY|File::CREAT|File::EXCL else 'w' end
  open(name, mode) do |f|
    f.write(body + "\n")
  end
  name
end