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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lolcommits/runner.rb', line 11

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

  if GitInfo.repo_root?
    self.vcs_info = GitInfo.new
  elsif MercurialInfo.repo_root?
    self.vcs_info = MercurialInfo.new
  end

  if vcs_info
    self.sha ||= vcs_info.sha
    self.message ||= vcs_info.message
  end

  return unless config

  self.capture_path       = config.capture_path(lolcommit_ext)
  self.lolcommit_path     = config.sha_path(sha, lolcommit_ext)
  self.lolcommit_gif_path = config.sha_path(sha, "gif") if capture_gif
end

Instance Attribute Details

#capture_delayObject

Returns the value of attribute capture_delay.



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

def capture_delay
  @capture_delay
end

#capture_deviceObject

Returns the value of attribute capture_device.



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

def capture_device
  @capture_device
end

#capture_durationObject

Returns the value of attribute capture_duration.



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

def capture_duration
  @capture_duration
end

#capture_gifObject

Returns the value of attribute capture_gif.



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

def capture_gif
  @capture_gif
end

#capture_pathObject

Returns the value of attribute capture_path.



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

def capture_path
  @capture_path
end

#capture_stealthObject

Returns the value of attribute capture_stealth.



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

def capture_stealth
  @capture_stealth
end

#capture_videoObject

Returns the value of attribute capture_video.



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

def capture_video
  @capture_video
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#lolcommit_gif_pathObject

Returns the value of attribute lolcommit_gif_path.



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

def lolcommit_gif_path
  @lolcommit_gif_path
end

#lolcommit_pathObject

Returns the value of attribute lolcommit_path.



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

def lolcommit_path
  @lolcommit_path
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#shaObject

Returns the value of attribute sha.



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

def sha
  @sha
end

#vcs_infoObject

Returns the value of attribute vcs_info.



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

def vcs_info
  @vcs_info
end

Instance Method Details

#capture_image?Boolean

Returns:

  • (Boolean)


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

def capture_image?
  capture_duration.to_i.zero?
end

#overlayObject

return MiniMagick overlay png for manipulation (or create one)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lolcommits/runner.rb', line 56

def overlay
  @overlay ||= begin
    source_path = capture_image? ? lolcommit_path : capture_path
    unless File.exist?(source_path)
      raise "too early to overlay, capture doesn't exist yet"
    end

    base = MiniMagick::Image.open(source_path)
    png_tempfile = MiniMagick::Utilities.tempfile(".png")
    debug("creating a new empty overlay png for lolcommit (#{base.dimensions.join('x')})")

    MiniMagick.convert do |convert|
      convert.size "#{base.width}x#{base.height}"
      convert.xc "transparent"
      convert << png_tempfile.path
    end

    debug "mehhh!"

    MiniMagick::Image.open(png_tempfile.path)
  end
end

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lolcommits/runner.rb', line 34

def run
  execute_plugins_for(:pre_capture)

  # main capture
  run_capture

  # capture must exist to run post capture methods
  unless File.exist?(capture_path)
    raise "failed to capture any image or video!"
  end

  run_post_capture
  run_capture_ready
rescue StandardError => e
  debug("#{e.class}: #{e.message}")
  exit 1
ensure
  debug "running cleanup"
  FileUtils.rm_f(capture_path)
end