# frozen_string_literal: true module GoNative module Utils class TemplateInflator autoload :FileUtils, 'fileutils' extend DSL::Serviceable def initialize(options) @options = options end def call Dir.glob('*/').each do |dir| FileUtils.cd(dir) call FileUtils.cd('..') dir_name = dir.delete_suffix('/') normalized_name = normalized_name(dir_name) FileUtils.mv(dir_name, normalized_name) if dir_name != normalized_name end inflate_files end def inflate_files Dir.glob("*#{TEMPLATE_FILES_EXTENSION}").each do |file| File.write(normalized_name(file), contents(file)) FileUtils.rm(file) end end def contents(file) content = File.read(file) Utils::ContentEvaluator.call(content, options) end def normalized_name(file_name) new_name = file_name.dup options.each do |key, value| new_name.gsub!(key.to_s.upcase, value) end new_name.delete_suffix(TEMPLATE_FILES_EXTENSION) end private attr_reader :options end end end