class ProxyTester::Actions::CreateFile
Attributes
data[R]
destination[R]
engine[R]
name[R]
options[R]
repository[R]
Public Class Methods
new(name, destination, data, options = {}, engine = ErbGenerator, repository = TemplateRepository.new)
click to toggle source
# File lib/proxy_tester/actions/create_file.rb, line 11 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
Public Instance Methods
run()
click to toggle source
# File lib/proxy_tester/actions/create_file.rb, line 20 def run if need_to_run? || options[:force] == true ProxyTester.ui_logger.warn "Creating file \"#{destination}\"." create_directories if options[:create_directories] == true file = template(name, ::File.new(destination, 'w'), data) FileUtils.chmod('+x', file) if options[:executable] == true else ProxyTester.ui_logger.warn "File \"#{destination}\" already exists. Do not create it again!." end end
Private Instance Methods
create_directories()
click to toggle source
# File lib/proxy_tester/actions/create_file.rb, line 35 def create_directories FileUtils.mkdir_p(::File.dirname(destination)) end
need_to_run?()
click to toggle source
# File lib/proxy_tester/actions/create_file.rb, line 50 def need_to_run? !::File.exists?(destination) end
template(local_name, local_destination, local_data)
click to toggle source
# File lib/proxy_tester/actions/create_file.rb, line 39 def template(local_name, local_destination, local_data) template = repository.find(local_name) generator = engine.new(local_data) generator.compile(template, local_destination) local_destination rescue Errno::ENOENT fail Exceptions::ErbTemplateIsUnknown, JSON.dump(message: "Unknown erb template \"#{template_path}\".") end