Class: GoNative::Utils::TemplateInflator
- Inherits:
-
Object
- Object
- GoNative::Utils::TemplateInflator
- Extended by:
- DSL::Serviceable
- Defined in:
- lib/gonative/utils/template_inflator.rb
Instance Method Summary collapse
- #call ⇒ Object
- #contents(file) ⇒ Object
- #inflate_files ⇒ Object
-
#initialize(options) ⇒ TemplateInflator
constructor
A new instance of TemplateInflator.
- #normalized_name(file_name) ⇒ Object
Constructor Details
#initialize(options) ⇒ TemplateInflator
Returns a new instance of TemplateInflator.
13 14 15 |
# File 'lib/gonative/utils/template_inflator.rb', line 13 def initialize() @options = end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gonative/utils/template_inflator.rb', line 17 def call Dir.glob('*/').each do |dir| dir_name = dir.delete_suffix('/') FileUtils.cd(dir_name) do call end normalized_name = normalized_name(dir_name) FileUtils.mv(dir_name, normalized_name) if dir_name != normalized_name end inflate_files end |
#contents(file) ⇒ Object
36 37 38 39 40 |
# File 'lib/gonative/utils/template_inflator.rb', line 36 def contents(file) content = File.read(file) context = OpenStruct.new() ERB.new(content).result(context.instance_eval { binding }) end |
#inflate_files ⇒ Object
29 30 31 32 33 34 |
# File 'lib/gonative/utils/template_inflator.rb', line 29 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
42 43 44 45 46 47 48 |
# File 'lib/gonative/utils/template_inflator.rb', line 42 def normalized_name(file_name) new_name = file_name.dup .each do |key, value| new_name.gsub!(key.to_s.upcase, value) end new_name.delete_suffix(TEMPLATE_FILES_EXTENSION) end |