Sha256: a564f9475eaa24fdefc1bd18268eedbe0290797e5cfe683a4407d72e7a47e229

Contents?: true

Size: 1.17 KB

Versions: 20

Compression:

Stored size: 1.17 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

20 entries across 20 versions & 1 rubygems

Version Path
gonative-cli-1.4.4 lib/gonative/utils/template_inflator.rb
gonative-cli-1.4.3 lib/gonative/utils/template_inflator.rb
gonative-cli-1.4.2 lib/gonative/utils/template_inflator.rb
gonative-cli-1.4.1 lib/gonative/utils/template_inflator.rb
gonative-cli-1.4.0 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.9 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.8 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.7 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.6 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.5 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.4 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.3 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.2 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.1 lib/gonative/utils/template_inflator.rb
gonative-cli-1.3.0 lib/gonative/utils/template_inflator.rb
gonative-cli-1.2.4 lib/gonative/utils/template_inflator.rb
gonative-cli-1.2.3 lib/gonative/utils/template_inflator.rb
gonative-cli-1.2.2 lib/gonative/utils/template_inflator.rb
gonative-cli-1.2.1 lib/gonative/utils/template_inflator.rb
gonative-cli-1.2.0 lib/gonative/utils/template_inflator.rb