Sha256: 55375ed3aea673704ea9ee308b5c5d7bffc0e5885bd7e1e6391027c272fcee14
Contents?: true
Size: 1.18 KB
Versions: 35
Compression:
Stored size: 1.18 KB
Contents
# 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
Version data entries
35 entries across 35 versions & 1 rubygems