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-0.7.13 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.12 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.11 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.10 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.9 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.8 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.7 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.6 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.5 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.4 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.3 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.2 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.1 lib/gonative/utils/template_inflator.rb
gonative-cli-0.7.0 lib/gonative/utils/template_inflator.rb
gonative-cli-0.6.0 lib/gonative/utils/template_inflator.rb