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

Version Path
gonative-cli-1.1.2 lib/gonative/utils/template_inflator.rb
gonative-cli-1.1.1 lib/gonative/utils/template_inflator.rb
gonative-cli-1.1.0 lib/gonative/utils/template_inflator.rb
gonative-cli-1.0.6 lib/gonative/utils/template_inflator.rb
gonative-cli-1.0.5 lib/gonative/utils/template_inflator.rb
gonative-cli-1.0.4 lib/gonative/utils/template_inflator.rb
gonative-cli-1.0.3 lib/gonative/utils/template_inflator.rb
gonative-cli-1.0.2 lib/gonative/utils/template_inflator.rb
gonative-cli-1.0.1 lib/gonative/utils/template_inflator.rb
gonative-cli-1.0.0 lib/gonative/utils/template_inflator.rb
gonative-cli-0.9.3 lib/gonative/utils/template_inflator.rb
gonative-cli-0.9.2 lib/gonative/utils/template_inflator.rb
gonative-cli-0.9.1 lib/gonative/utils/template_inflator.rb
gonative-cli-0.9.0 lib/gonative/utils/template_inflator.rb
gonative-cli-0.8.1 lib/gonative/utils/template_inflator.rb
gonative-cli-0.8.0 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.17 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.16 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.15 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.14 lib/gonative/utils/template_inflator.rb