Sha256: 003b99f157c703d088599e9b7796eacab4bf132ea6a6f34fbd0023539a861423
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
# encoding: utf-8 module LocalPac module Actions class CreateFile private attr_reader :name, :destination, :data, :options, :engine, :repository public def initialize(name, destination, data, options = {}, engine = ErbGenerator, repository = TemplateRepository.new) @name = name @destination = File.expand_path(destination) @data = data @options = options @engine = engine @repository = repository end def run if need_to_run? || options[:force] == true LocalPac.ui_logger.warn "Creating file \"#{destination}\"." file = template(name, destination, data) FileUtils.chmod('+x', file) if options[:executable] == true else LocalPac.ui_logger.warn "File \"#{destination}\" already exists. Do not create it again!." end end private def template(local_name, local_destination, local_data) template = repository.find(local_name) generator = engine.new(local_data) generator.compile(template, ::File.new(local_destination, 'w')) local_destination rescue Errno::ENOENT fail Exceptions::ErbTemplateIsUnknown, "Unknown erb template \"#{template_path}\"." end def need_to_run? !File.exists?(destination) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
local_pac-0.1.11 | lib/local_pac/actions/create_file.rb |
local_pac-0.1.10 | lib/local_pac/actions/create_file.rb |