class Boop

Constants

VERSION

Public Class Methods

new(base_url, repo_dir) click to toggle source
# File lib/boop.rb, line 5
def initialize(base_url, repo_dir)
  @base_url = base_url
  @repo_dir = File.expand_path(repo_dir)
end

Public Instance Methods

file(name, contents) click to toggle source
# File lib/boop.rb, line 18
def file(name, contents)
  save_file(name, contents)
end
html(name, contents) click to toggle source
# File lib/boop.rb, line 14
def html(name, contents)
  save(:html, name, contents)
end
paste(name, contents) click to toggle source
# File lib/boop.rb, line 10
def paste(name, contents)
  save(:txt, name, contents)
end

Private Instance Methods

commit_and_push!(filename) click to toggle source
# File lib/boop.rb, line 41
def commit_and_push!(filename)
  Dir.chdir(@repo_dir) do
    `git add #{filename}`
    `git commit -q -m "Add paste: #{filename}"`
    `git push -q`
  end
end
print_url(filename) click to toggle source
save(file_extension, name, contents) click to toggle source
# File lib/boop.rb, line 23
def save(file_extension, name, contents)
  name ||= SecureRandom.uuid.tr('-i', '')

  filename = "#{name}.#{file_extension}"

  save_file(filename, contents)
end
save_file(filename, contents) click to toggle source
# File lib/boop.rb, line 31
def save_file(filename, contents)
  path = File.join(@repo_dir, filename)

  File.open(path, 'w') { |f| f.write contents }

  commit_and_push!(filename)

  print_url(filename)
end