Class: Lolcommits::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/lolcommits/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lolcommits/runner.rb', line 9

def initialize(attributes = {})
  attributes.each do |attr, val|
    send("#{attr}=", val)
  end

  return unless sha.nil? || message.nil?
  if GitInfo.repo_root?
    self.vcs_info = GitInfo.new
  elsif MercurialInfo.repo_root?
    self.vcs_info = MercurialInfo.new
  else
    raise('Unknown VCS')
  end

  self.sha      = vcs_info.sha if sha.nil?
  self.message  = vcs_info.message if message.nil?
end

Instance Attribute Details

#capture_animateObject

Returns the value of attribute capture_animate.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def capture_animate
  @capture_animate
end

#capture_delayObject

Returns the value of attribute capture_delay.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def capture_delay
  @capture_delay
end

#capture_deviceObject

Returns the value of attribute capture_device.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def capture_device
  @capture_device
end

#capture_stealthObject

Returns the value of attribute capture_stealth.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def capture_stealth
  @capture_stealth
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def config
  @config
end

#main_imageObject

Returns the value of attribute main_image.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def main_image
  @main_image
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def message
  @message
end

#shaObject

Returns the value of attribute sha.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def sha
  @sha
end

#snapshot_locObject

Returns the value of attribute snapshot_loc.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def snapshot_loc
  @snapshot_loc
end

#vcs_infoObject

Returns the value of attribute vcs_info.



5
6
7
# File 'lib/lolcommits/runner.rb', line 5

def vcs_info
  @vcs_info
end

Instance Method Details

#capture_animated?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/lolcommits/runner.rb', line 80

def capture_animated?
  capture_animate > 0
end

#runObject

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lolcommits/runner.rb', line 30

def run
  # do plugins that need to happen before capture
  plugin_manager.plugins_for(:precapture).each do |plugin|
    plugin.new(self).execute_precapture
  end

  # 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::Plugin::Loltext.new(self).execute_postcapture

    # do plugins that need to happen after capture
    plugin_manager.plugins_for(:postcapture).each do |plugin|
      plugin.new(self).execute_postcapture
    end

    # do things that should happen last
    cleanup!
  else
    debug 'Runner: failed to capture a snapshot'
    exit 1
  end
end

#run_captureObject

the main capture



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lolcommits/runner.rb', line 64

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(capture_animated?).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