Class: Vipergen::Generator
- Inherits:
-
Object
- Object
- Vipergen::Generator
- Defined in:
- lib/vipergen/generator.rb
Overview
Cosntants
Constant Summary collapse
- LANGUAGES =
Constants
["swift", "objc"]
- REPLACEMENT_KEY =
"VIPER"- AUTHOR_REPLACEMENT_KEY =
"AUTHOR"- YEAR_REPLACEMENT_KEY =
"YEAR"- DATE_REPLACEMENT_KEY =
"DATE"- PROJECT_REPLACEMENT_KEY =
"PROJECT"- COMPANY_REPLACEMENT_KEY =
"COMPANY"- SWIFT_MODULE_REPLACEMENT_KEY =
"SWIFT_MODULE"
Class Method Summary collapse
-
.generate_viper(template, language, name, path, author, project, company, swift_module) ⇒ Object
Main method that generate the VIPER files structure.
-
.rename_file(file, name, author, project, company, swift_module) ⇒ Object
Rename a given file - It renames the name of the file - It renames the content of the file.
-
.rename_file_content(filename, name, author, project, company, swift_module) ⇒ Object
Rename the file content @return: An String with the every VIPER replaced by ‘name’.
-
.rename_files(files, name, author, project, company, swift_module) ⇒ Object
Rename all the files in the files array - It renames the name of the file - It renames the content of the file.
Class Method Details
.generate_viper(template, language, name, path, author, project, company, swift_module) ⇒ Object
Main method that generate the VIPER files structure
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vipergen/generator.rb', line 15 def self.generate_viper(template, language, name, path, , project, company, swift_module) puts "Generating VIPER-Module" puts "Template: #{template}" puts "Language: #{language}" puts "Name: #{name}" puts "Path: #{path}" puts "Author: #{}" puts "Project: #{project}" puts "Company: #{company}" puts "Module: #{swift_module}" path_from = Vipergen::FileManager.path_from(template, language) path_to = Vipergen::FileManager.destination_viper_path(path, name) Vipergen::FileManager.copy(path_from, path_to) files = Vipergen::FileManager.files_in_path(path_to) rename_files(files, name, , project, company, swift_module) end |
.rename_file(file, name, author, project, company, swift_module) ⇒ Object
Rename a given file
-
It renames the name of the file
-
It renames the content of the file
45 46 47 48 49 |
# File 'lib/vipergen/generator.rb', line 45 def self.rename_file(file, name, , project, company, swift_module) new_path = file.gsub((Vipergen::Generator::REPLACEMENT_KEY), name) Vipergen::FileManager.move(file, new_path) rename_file_content(new_path, name, , project, company, swift_module) end |
.rename_file_content(filename, name, author, project, company, swift_module) ⇒ Object
Rename the file content @return: An String with the every VIPER replaced by ‘name’
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vipergen/generator.rb', line 53 def self.rename_file_content(filename, name, , project, company, swift_module) # Reading content file = File.open(filename, "rb") content = file.read file.close # Replacing content content = content.gsub((Vipergen::Generator::REPLACEMENT_KEY), name) content = content.gsub((Vipergen::Generator::AUTHOR_REPLACEMENT_KEY), ) content = content.gsub((Vipergen::Generator::PROJECT_REPLACEMENT_KEY), project) content = content.gsub((Vipergen::Generator::COMPANY_REPLACEMENT_KEY), company) content = content.gsub((Vipergen::Generator::SWIFT_MODULE_REPLACEMENT_KEY), swift_module) content = content.gsub((Vipergen::Generator::YEAR_REPLACEMENT_KEY), "#{Time.new.year}") content = content.gsub((Vipergen::Generator::DATE_REPLACEMENT_KEY), "#{Time.now.strftime("%d/%m/%y")}") # Saving content with replaced string File.open(filename, "w+") do |file| file.write(content) end end |
.rename_files(files, name, author, project, company, swift_module) ⇒ Object
Rename all the files in the files array
-
It renames the name of the file
-
It renames the content of the file
35 36 37 38 39 40 |
# File 'lib/vipergen/generator.rb', line 35 def self.rename_files(files, name, , project, company, swift_module) files.each do |file| raise SyntaxError unless file.include? (Vipergen::Generator::REPLACEMENT_KEY) rename_file(file, name, , project, company, swift_module) end end |