class Idlc::Workspace

Attributes

tmp_dir[RW]

Public Class Methods

new() click to toggle source
# File lib/idlc-sdk-core/workspace.rb, line 14
def initialize
  @tmp_dir = Dir.mktmpdir('ws-temp')
end
zip_folder(src, out) click to toggle source
# File lib/idlc-sdk-core/workspace.rb, line 6
def zip_folder(src, out)
  zf = ZipFileGenerator.new(src, out)
  zf.write
end

Public Instance Methods

add(path) click to toggle source
# File lib/idlc-sdk-core/workspace.rb, line 40
def add(path)
  parent_dir = path.split('/')[0..-2].join('/')
  FileUtils.mkdir_p("#{@tmp_dir}/#{parent_dir}")
  FileUtils.cp_r(path, "#{@tmp_dir}/#{path}")
end
cleanup() click to toggle source
# File lib/idlc-sdk-core/workspace.rb, line 22
def cleanup
  debug("keeping directory: #{@tmp_dir} for dubugging")
  return if ENV['DEBUG']

  FileUtils.rm_rf(@tmp_dir)
end
empty?() click to toggle source
# File lib/idlc-sdk-core/workspace.rb, line 18
def empty?
  !Dir.exist? @tmp_dir
end
flatten(base_path, file_ext) click to toggle source
# File lib/idlc-sdk-core/workspace.rb, line 29
def flatten(base_path, file_ext)
  Dir["#{base_path}/**/*.#{file_ext}"].each do |file|
    # get the filename and parent dir
    filename = file.tr('/', '-')

    # copy the files to a single temp directory.
    debug("copying #{file} to #{@tmp_dir}/#{filename} ...")
    FileUtils.cp(file, "#{@tmp_dir}/#{filename}")
  end
end