Class: Ace::Demo::Organisms::DemoAttacher

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/demo/organisms/demo_attacher.rb

Instance Method Summary collapse

Constructor Details

#initialize(uploader: Molecules::GhAssetUploader.new, formatter: Atoms::DemoCommentFormatter, poster: Molecules::DemoCommentPoster.new, agg_executor: Molecules::AggExecutor.new, agg_bin: Demo.config["agg_bin"], agg_font_family: Demo.config["agg_font_family"], clock: -> { Time.now }) ⇒ DemoAttacher

Returns a new instance of DemoAttacher.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ace/demo/organisms/demo_attacher.rb', line 9

def initialize(uploader: Molecules::GhAssetUploader.new,
  formatter: Atoms::DemoCommentFormatter,
  poster: Molecules::DemoCommentPoster.new,
  agg_executor: Molecules::AggExecutor.new,
  agg_bin: Demo.config["agg_bin"],
  agg_font_family: Demo.config["agg_font_family"],
  clock: -> { Time.now })
  @uploader = uploader
  @formatter = formatter
  @poster = poster
  @agg_executor = agg_executor
  @agg_bin = agg_bin || "agg"
  @agg_font_family = agg_font_family
  @clock = clock
end

Instance Method Details

#attach(file:, pr:, dry_run: false) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ace/demo/organisms/demo_attacher.rb', line 25

def attach(file:, pr:, dry_run: false)
  raise ArgumentError, "Recording file not found: #{file}" unless File.exist?(file)

  prepared = prepare_upload(file: file, dry_run: dry_run)
  begin
    demo_name = prepared.fetch(:demo_name)
    ext = prepared.fetch(:format)
    upload = @uploader.upload(file_path: prepared.fetch(:file_path), dry_run: dry_run)
    comment_body = @formatter.format(
      demo_name: demo_name,
      asset_url: upload.fetch(:asset_url),
      recorded_at: @clock.call,
      format: ext
    )

    @poster.post(pr: pr, comment_body: comment_body, dry_run: dry_run)

    {
      dry_run: dry_run,
      pr: pr,
      demo_name: demo_name,
      asset_name: upload.fetch(:asset_name),
      asset_url: upload.fetch(:asset_url),
      comment_body: comment_body
    }
  ensure
    cleanup_temporary_file(prepared)
  end
end