Sha256: a2b6d4ef799539979aa685f35e614537050c80b95c11a5d8cddea6bef7f8d3c5

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# ==========================================
#   CMock Project - Automatic Mock Generation for C
#   Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
#   [Released under MIT License. Please refer to license.txt for details]
# ==========================================

class CMockFileWriter

  attr_reader :config

  def initialize(config)
    @config = config
  end

  def create_subdir(subdir)
    if !Dir.exists?("#{@config.mock_path}/")
      require 'fileutils'
      FileUtils.mkdir_p "#{@config.mock_path}/"
    end
    if subdir && !Dir.exists?("#{@config.mock_path}/#{subdir+'/' if subdir}")
      require 'fileutils'
      FileUtils.mkdir_p "#{@config.mock_path}/#{subdir+'/' if subdir}"
    end
  end

  def create_file(filename, subdir)
    raise "Where's the block of data to create?" unless block_given?
    full_file_name_temp = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}.new"
    full_file_name_done = "#{@config.mock_path}/#{subdir+'/' if subdir}#{filename}"
    File.open(full_file_name_temp, 'w') do |file|
      yield(file, filename)
    end
    update_file(full_file_name_done, full_file_name_temp)
  end

  private ###################################

  def update_file(dest, src)
    require 'fileutils'
    FileUtils.rm(dest) if (File.exist?(dest))
    FileUtils.cp(src, dest)
    FileUtils.rm(src)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ceedling-0.29.1 vendor/cmock/lib/cmock_file_writer.rb
ceedling-0.29.0 vendor/cmock/lib/cmock_file_writer.rb