class GitPresenter::Controller

Constants

CONFIG_FILE

Public Class Methods

new(file_path) click to toggle source
# File lib/git_presenter/controller.rb, line 4
def initialize(file_path)
  @presentation_dir = file_path
end

Public Instance Methods

initialise_presentation() click to toggle source
# File lib/git_presenter/controller.rb, line 8
def initialise_presentation
  yaml = {"slides" => create_slides, "branch" => current_branch}.to_yaml
  File.open(presentation_file_location, "w") do |file|
    file.write(yaml)
  end
  puts "Presentation has been initalised"
  puts "run 'git-presenter start' to begin the presentation"
end
load_presentation() click to toggle source
# File lib/git_presenter/controller.rb, line 17
def load_presentation
  yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
  GitPresenter::Presentation.new(yaml)
end
start_presentation() click to toggle source
# File lib/git_presenter/controller.rb, line 22
def start_presentation
  presenter = load_presentation
  puts presenter.start
  presenter
end
update_presentation() click to toggle source
# File lib/git_presenter/controller.rb, line 28
def update_presentation
  yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
  slides = create_slides(yaml['slides'].last["slide"]["commit"])
  yaml["slides"] = yaml["slides"] + slides
  yaml["slides"].uniq!
  write_file(yaml.to_yaml)
  puts "Your presentation has been updated"
end

Private Instance Methods

create_slides(last_commit=nil) click to toggle source
# File lib/git_presenter/controller.rb, line 49
def create_slides(last_commit=nil)
  repo = Git.open(".")
  commits = repo.log.to_a.reverse
  commits = commits.drop_while{|commit| commit.sha != last_commit}[1..-1] unless last_commit.nil?
  commits.map do |commit|
    {"slide" =>
       {"commit"  => commit.sha,
       "message" => commit.message}
    }
  end
end
current_branch() click to toggle source
# File lib/git_presenter/controller.rb, line 61
def current_branch
  `git rev-parse --abbrev-ref HEAD`.strip
end
presentation_file_location() click to toggle source
# File lib/git_presenter/controller.rb, line 45
def presentation_file_location
  File.join(@presentation_dir, CONFIG_FILE)
end
write_file(yaml) click to toggle source
# File lib/git_presenter/controller.rb, line 39
def write_file(yaml)
  File.open(presentation_file_location, "w") do |file|
    file.write(yaml)
  end
end