Module: Branch::Name::Projectable
Constant Summary
Constants included from Normalizable
Normalizable::BRANCH_NAME_REGEX, Normalizable::DEFAULT_PROJECT_FOLDER_TOKEN_SEPARATOR, Normalizable::PROJECT_FOLDER_REGEX, Normalizable::PROJECT_FOLDER_TOKEN_SEPARATORS
Instance Method Summary collapse
- #create_project!(branch_name) ⇒ Object
- #create_project_files!(project_folder) ⇒ Object
- #project_folder_for(branch_name) ⇒ Object
Methods included from Normalizable
#normalize_branch_name, #project_folder_name_from
Methods included from Locatable
global_folder?, home_folder, local_folder, project_folder, temp_folder
Instance Method Details
#create_project!(branch_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/branch/name/projectable.rb', line 13 def create_project!(branch_name) raise 'options[:project] is false' unless [:project] project_folder = project_folder_for branch_name if Dir.exist? project_folder puts "Project folder \"#{project_folder}\" already exists" create_project_files!(project_folder) return end FileUtils.mkdir_p(project_folder) create_project_files!(project_folder) project_files = [:project_files] if project_files.blank? puts "Project folder \"#{project_folder}\" was created.".green else puts "Project folder \"#{project_folder}\" was created with project files:".green project_files.each do |project_file| puts "- #{project_file}".green end end end |
#create_project_files!(project_folder) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/branch/name/projectable.rb', line 38 def create_project_files!(project_folder) raise 'options[:project] is false' unless [:project] raise "Project folder \"#{project_folder}\" does not exist" unless Dir.exist? project_folder project_files = [:project_files] return if project_files.blank? project_files.each do |project_file| full_file_name = File.join(project_folder, project_file) next if File.exist? full_file_name FileUtils.touch full_file_name puts "Created project file \"#{full_file_name}\"" if [:verbose] end end |
#project_folder_for(branch_name) ⇒ Object
56 57 58 59 60 |
# File 'lib/branch/name/projectable.rb', line 56 def project_folder_for(branch_name) branch_name = project_folder_name_from branch_name project_location = Time.new.strftime([:project_location]) File.join(project_location, branch_name) end |