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 = {}, config) ⇒ FileCreator
constructor
A new instance of FileCreator.
- #logger ⇒ Object
- #print_file_content(prefix, suffix) ⇒ Object
- #templater_options(target) ⇒ Object
Constructor Details
#initialize(options = {}, config) ⇒ FileCreator
Returns a new instance of FileCreator.
27 28 29 30 |
# File 'lib/ccios/file_creator.rb', line 27 def initialize( = {}, config) @options = @config = config 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
63 64 65 66 67 68 69 |
# File 'lib/ccios/file_creator.rb', line 63 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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ccios/file_creator.rb', line 45 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(, @config.templates.path) 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
41 42 43 |
# File 'lib/ccios/file_creator.rb', line 41 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
71 72 73 74 75 76 77 78 79 |
# File 'lib/ccios/file_creator.rb', line 71 def print_file_content(prefix, suffix) file_name = suffix + '.swift' code_templater = CodeTemplater.new(@options, @config.templates.path) template = code_templater.content_for_suffix(prefix, suffix) logger.info "Add this snippet to #{file_name}" logger.info template end |
#templater_options(target) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/ccios/file_creator.rb', line 32 def (target) defaults = { project_name: target.display_name, full_username: git_username, date: DateTime.now.strftime("%d/%m/%Y"), } defaults.merge(@options) end |