class PurrPr::Editor

Attributes

content[R]
subject[R]

Public Class Methods

new(subject, content: '') click to toggle source
# File lib/purr_pr/editor.rb, line 18
def initialize(subject, content: '')
  @subject = subject.to_s
  @content = content
end

Public Instance Methods

append(text) click to toggle source
# File lib/purr_pr/editor.rb, line 32
def append(text)
  @content += text
end
clear() click to toggle source
# File lib/purr_pr/editor.rb, line 48
def clear
  @content = ''
end
confirm() click to toggle source
# File lib/purr_pr/editor.rb, line 70
    def confirm
      text = <<~TEXT
        Current #{subject}:

        #{content}

        Continue? (Y/N)
      TEXT

      ask_yn(text, decline: -> { interrupt })
    end
Also aliased as: confirmation
confirmation()
Alias for: confirm
delete(text) click to toggle source
# File lib/purr_pr/editor.rb, line 44
def delete(text)
  replace(text, with: '')
end
edit(format: :md) click to toggle source
# File lib/purr_pr/editor.rb, line 52
def edit(format: :md)
  name = subject + SecureRandom.hex(8)
  format = ".#{format}" unless format.nil?

  file = Tempfile.new([name, format])
  file.write(content)
  file.rewind

  editor = `echo $VISUAL`.chomp || `echo $EDITOR`.chomp || 'vim'

  system("#{editor} #{file.path}")

  @content = file.read
ensure
  file.close
end
Also aliased as: editor
editor(format: :md)
Alias for: edit
evaluate(&block) click to toggle source
# File lib/purr_pr/editor.rb, line 23
def evaluate(&block)
  @caller_binding = eval('self', block.binding)
  instance_eval(&block)
end
method_missing(method, *args, &block) click to toggle source
# File lib/purr_pr/editor.rb, line 28
def method_missing(method, *args, &block)
  @caller_binding.send(method, *args, &block)
end
prepend(text) click to toggle source
# File lib/purr_pr/editor.rb, line 36
def prepend(text)
  @content = text + @content
end
replace(text, with: '') click to toggle source
# File lib/purr_pr/editor.rb, line 40
def replace(text, with: '')
  @content.gsub!(text, with)
end
use_template(path = '.github/pull_request_template.md') click to toggle source
# File lib/purr_pr/editor.rb, line 83
def use_template(path = '.github/pull_request_template.md')
  @content = read_file(path)
end