class Lolcommits::Runner

Attributes

capture_animate[RW]
capture_delay[RW]
capture_device[RW]
capture_stealth[RW]
config[RW]
git_info[RW]
main_image[RW]
message[RW]
sha[RW]
snapshot_loc[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/lolcommits/runner.rb, line 11
def initialize(attributes = {})
  attributes.each do |attr, val|
    send("#{attr}=", val)
  end

  return unless sha.nil? || message.nil?
  self.git_info = GitInfo.new
  self.sha      = git_info.sha if sha.nil?
  self.message  = git_info.message if message.nil?
end
plugins() click to toggle source
# File lib/lolcommits/runner.rb, line 70
def self.plugins
  Lolcommits::Plugin.subclasses
end

Public Instance Methods

animate?() click to toggle source
# File lib/lolcommits/runner.rb, line 91
def animate?
  capture_animate && (capture_animate.to_i > 0)
end
plugins_for(position) click to toggle source
# File lib/lolcommits/runner.rb, line 66
def plugins_for(position)
  self.class.plugins.select { |p| p.runner_order == position }
end
run() click to toggle source

wrap run to handle things that should happen before and after this used to be handled with ActiveSupport::Callbacks, but now we're just using a simple procedural list

# File lib/lolcommits/runner.rb, line 25
def run
  # do things that need to happen before capture and plugins

  # do native plugins that need to happen before capture
  plugins_for(:precapture).each do |plugin|
    debug "Runner: precapture about to execute #{plugin}"
    plugin.new(self).execute_precapture
  end

  # do gem plugins that need to happen before capture?

  # do main capture to snapshot_loc
  run_capture

  # check capture succeded, file must exist
  if File.exist?(snapshot_loc)

    ## resize snapshot first
    resize_snapshot!

    # do native plugins that need to happen immediately after capture and
    # resize this is effectively the "image processing" phase for now,
    # reserve just for us and handle manually...?
    Lolcommits::Loltext.new(self).execute_postcapture

    # do native plugins that need to happen after capture
    plugins_for(:postcapture).each do |plugin|
      debug "Runner: postcapture about to execute #{plugin}"
      plugin.new(self).execute_postcapture
    end

    # do gem plugins that need to happen after capture?

    # do things that should happen last
    cleanup!
  else
    debug 'Runner: failed to capture a snapshot'
    exit 1
  end
end
run_capture() click to toggle source

the main capture

# File lib/lolcommits/runner.rb, line 75
def run_capture
  puts '*** Preserving this moment in history.' unless capture_stealth
  self.snapshot_loc = config.raw_image(image_file_type)
  self.main_image   = config.main_image(sha, image_file_type)

  capturer = Platform.capturer_class(animate?).new(
    :capture_device    => capture_device,
    :capture_delay     => capture_delay,
    :snapshot_location => snapshot_loc,
    :video_location    => config.video_loc,
    :frames_location   => config.frames_loc,
    :animated_duration => capture_animate
  )
  capturer.capture
end

Private Instance Methods

image_file_type() click to toggle source

def capturer_class

capturer_module = 'Lolcommits'
Object.const_get(capturer_module).const_get(Platform.capturer_class(animate?))

end

# File lib/lolcommits/runner.rb, line 102
def image_file_type
  animate? ? 'gif' : 'jpg'
end