class Ninny::Commands::CreateDatedBranch
Attributes
branch_type[R]
should_delete_old_branches[R]
Public Class Methods
new(options)
click to toggle source
# File lib/ninny/commands/create_dated_branch.rb, line 8 def initialize(options) @branch_type = options[:branch_type] || Git::STAGING_PREFIX @should_delete_old_branches = options[:delete_old_branches] end
Public Instance Methods
branch_name()
click to toggle source
Public: The name of the branch to create
# File lib/ninny/commands/create_dated_branch.rb, line 31 def branch_name with_branch_type do "#{branch_type}.#{date_suffix}" end end
create_branch()
click to toggle source
Public: Create the desired branch
# File lib/ninny/commands/create_dated_branch.rb, line 20 def create_branch prompt.say "Attempting to create branch #{branch_name}." Ninny.git.new_branch(branch_name, Ninny.project_config.deploy_branch) end
date_suffix()
click to toggle source
Public: The date suffix to append to the branch name
# File lib/ninny/commands/create_dated_branch.rb, line 26 def date_suffix Date.today.strftime('%Y.%m.%d') end
delete_old_branches()
click to toggle source
Public: If necessary, and if user opts to, delete old branches of its type
# File lib/ninny/commands/create_dated_branch.rb, line 38 def delete_old_branches return unless extra_branches.any? should_delete = should_delete_old_branches || prompt.yes?( "Do you want to delete the old #{branch_type} branch(es)? (#{extra_branches.join(', ')})" ) return unless should_delete extra_branches.each do |extra| Ninny.git.delete_branch(extra) end end
execute(output: $stdout)
click to toggle source
# File lib/ninny/commands/create_dated_branch.rb, line 13 def execute(output: $stdout) create_branch delete_old_branches output.puts "Branch #{branch_name} successfully created." end
extra_branches()
click to toggle source
Public: The list of extra branches that exist after creating the new branch
Returns an Array of Strings of the branch names
# File lib/ninny/commands/create_dated_branch.rb, line 55 def extra_branches with_branch_type do Ninny.git.branches_for(branch_type).reject { |branch| branch.name == branch_name } end end
with_branch_type() { || ... }
click to toggle source
# File lib/ninny/commands/create_dated_branch.rb, line 61 def with_branch_type case branch_type when Git::DEPLOYABLE_PREFIX, Git::STAGING_PREFIX, Git::QAREADY_PREFIX yield else raise InvalidBranchType, "'#{branch_type}' is not a valid branch type" end end