Class: FileCreator
- Inherits:
-
Object
- Object
- FileCreator
- Defined in:
- lib/ccios/file_creator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_empty_directory(group) ⇒ Object
- #create_file(prefix, suffix, group, target) ⇒ Object
- #git_username ⇒ Object
-
#initialize(options = {}) ⇒ FileCreator
constructor
A new instance of FileCreator.
- #logger ⇒ Object
- #print_file_content(prefix, suffix) ⇒ Object
- #templater_options(target) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FileCreator
Returns a new instance of FileCreator.
27 28 29 |
# File 'lib/ccios/file_creator.rb', line 27 def initialize( = {}) @options = end |
Class Method Details
.logger ⇒ Object
19 20 21 |
# File 'lib/ccios/file_creator.rb', line 19 def self.logger @@logger ||= create_logger end |
Instance Method Details
#create_empty_directory(group) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/ccios/file_creator.rb', line 62 def create_empty_directory(group) dirname = group.real_path FileUtils.mkdir_p dirname unless File.directory?(dirname) git_keep_path = File.join(dirname, ".gitkeep") FileUtils.touch(git_keep_path) if Dir.empty?(dirname) end |
#create_file(prefix, suffix, group, target) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ccios/file_creator.rb', line 44 def create_file(prefix, suffix, group, target) file_path = File.join(group.real_path, prefix + suffix + '.swift') raise "File #{file_path} already exists" if File.exist?(file_path) dirname = File.dirname(file_path) FileUtils.mkdir_p dirname unless File.directory?(dirname) file = File.new(file_path, 'w') = (target) code_templater = CodeTemplater.new() file_content = code_templater.content_for_suffix(prefix, suffix) file.puts(file_content) file.close file_ref = group.new_reference(file_path) target.add_file_references([file_ref]) end |
#git_username ⇒ Object
40 41 42 |
# File 'lib/ccios/file_creator.rb', line 40 def git_username `git config user.name`.strip end |
#logger ⇒ Object
23 24 25 |
# File 'lib/ccios/file_creator.rb', line 23 def logger FileCreator.logger end |
#print_file_content(prefix, suffix) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/ccios/file_creator.rb', line 70 def print_file_content(prefix, suffix) file_name = suffix + '.swift' code_templater = CodeTemplater.new(@options) template = code_templater.content_for_suffix(prefix, suffix) logger.info "Add this snippet to #{file_name}" logger.info template end |
#templater_options(target) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ccios/file_creator.rb', line 31 def (target) defaults = { project_name: target.display_name, full_username: git_username, date: DateTime.now.strftime("%d/%m/%Y"), } defaults.merge(@options) end |