class Papa::Helper::Vi

Attributes

branches[RW]
path[RW]

Public Class Methods

new() click to toggle source
# File lib/papa/helper/vi.rb, line 9
def initialize
  @path = Helper::Path.generate_vi_file_path
  @branches = []
end

Public Instance Methods

run() click to toggle source
# File lib/papa/helper/vi.rb, line 14
def run
  initialize_file
  prompt_vi
  read_from_file
  delete_file
  validate_branches
  branches
end

Private Instance Methods

delete_file() click to toggle source
# File lib/papa/helper/vi.rb, line 53
def delete_file
  Command::Base.new("rm #{path}", silent: true).run
end
initialize_file() click to toggle source
# File lib/papa/helper/vi.rb, line 25
      def initialize_file
        content = <<-CONTENT


# Add your branches here. One branch name per line.
# Lines starting in pound (#) will be ignored
# Sample:
# feature/1-add-butterfree-gem
# feature/2-add-beedrill-gem
        CONTENT
        File.open(path, 'w') { |file| file.write(content) }
      end
prompt_vi() click to toggle source
# File lib/papa/helper/vi.rb, line 38
def prompt_vi
  system('vi', path)
end
read_from_file() click to toggle source
# File lib/papa/helper/vi.rb, line 42
def read_from_file
  @branches = File.read(path).chomp.split("\n").map do |branch|
    branch.strip!
    if branch.empty? || branch[0] == '#'
      nil
    else
      branch
    end
  end.compact.uniq
end
validate_branches() click to toggle source
# File lib/papa/helper/vi.rb, line 57
def validate_branches
  if @branches.empty?
    Helper::Output.failure 'No branches specified.'
    exit 1
  end
end