class FileCreator
Public Class Methods
logger()
click to toggle source
# File lib/ccios/file_creator.rb, line 19 def self.logger @@logger ||= create_logger end
new(options = {})
click to toggle source
# File lib/ccios/file_creator.rb, line 27 def initialize(options = {}) @options = options end
Private Class Methods
create_logger()
click to toggle source
# File lib/ccios/file_creator.rb, line 82 def self.create_logger logger = Logger.new(STDOUT) logger.level = Logger::DEBUG logger.formatter = proc { |severity, datetime, progname, msg| msg + "\n" } logger end
Public Instance Methods
create_empty_directory(group)
click to toggle source
# 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)
click to toggle source
# 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') templater_options = templater_options(target) code_templater = CodeTemplater.new(templater_options) 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()
click to toggle source
# File lib/ccios/file_creator.rb, line 40 def git_username `git config user.name`.strip end
logger()
click to toggle source
# File lib/ccios/file_creator.rb, line 23 def logger FileCreator.logger end
print_file_content(prefix, suffix)
click to toggle source
# 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)
click to toggle source
# File lib/ccios/file_creator.rb, line 31 def templater_options(target) defaults = { project_name: target.display_name, full_username: git_username, date: DateTime.now.strftime("%d/%m/%Y"), } defaults.merge(@options) end