class Rokkin

Public Class Methods

containerize(path, options={:force => false}) click to toggle source

Copies assets from lib/assets to path

# File lib/rokkin.rb, line 7
  def self.containerize(path, options={:force => false})
    bin_path    = File.expand_path(File.dirname(__FILE__))
    asset_path  = File.join(bin_path, "..", "lib", "assets")
    assets      = Dir.entries(asset_path) - ['.', '..']

    asset_list = assets.map do |filename|
      File.join(asset_path, filename)
    end

    # Are we going to overwrite an existing file?
    existing_files = assets - (assets - Dir.entries(path))

    if options[:force] || existing_files.empty?
      begin
        FileUtils.cp(asset_list, path, :preserve => true)
      rescue Errno::EACCES => e
        raise RokkinError.new(e.message)
      end
    else
      message = RokkinHelper.strip_heredoc <<-MSG
        Cannot overwrite the following files: #{existing_files}
        Remove files or retry with --force
      MSG
      raise RokkinError.new(message)
    end
  end