Class: GoNative::Utils::TemplateInflator

Inherits:
Object
  • Object
show all
Extended by:
DSL::Serviceable
Defined in:
lib/gonative/utils/template_inflator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TemplateInflator

Returns a new instance of TemplateInflator.



10
11
12
# File 'lib/gonative/utils/template_inflator.rb', line 10

def initialize(options)
  @options = options
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gonative/utils/template_inflator.rb', line 14

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

#contents(file) ⇒ Object



33
34
35
36
# File 'lib/gonative/utils/template_inflator.rb', line 33

def contents(file)
  content = File.read(file)
  Utils::ContentEvaluator.call(content, options)
end

#inflate_filesObject



26
27
28
29
30
31
# File 'lib/gonative/utils/template_inflator.rb', line 26

def inflate_files
  Dir.glob("*#{TEMPLATE_FILES_EXTENSION}").each do |file|
    File.write(normalized_name(file), contents(file))
    FileUtils.rm(file)
  end
end

#normalized_name(file_name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/gonative/utils/template_inflator.rb', line 38

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