This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.rb
58 lines (51 loc) · 2.04 KB
/
process.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
54
55
56
57
58
# frozen_string_literal: true
module Derivative
module Rodeo
##
# This class is responsible for processing the given {#derivative} in the given {#arena}
# and then requesting that the {#arena} process the next chain link after the given
# {#derivative}.
#
# @see .call
class Process
##
# @api public
#
# This is some of the core conceptual logic of the application:
#
# - I have the file locally…
# - failing that, I get the remote…
# - failing that I generate it…
# - failing that I raise [#Exceptions::FailureToLocateDerivativeError]
# - and if no exception is raised, I proceed with processing the next derivative.
#
# @param derivative [Derivative::Rodeo::Step::BaseStep]
# @param arena [Derivative::Rodeo::Arena]
#
# @raise [Derivative::Rodeo::Exceptions::FailureToLocateDerivativeError] when we are
# unable to find (or generate) the derivative in the given arena.
def self.call(derivative:, arena:)
new(derivative: derivative, arena: arena).call
end
def initialize(derivative:, arena:)
@derivative = Rodeo.Step(derivative)
@arena = arena
end
attr_reader :derivative, :arena
delegate :process_next_chain_link_after!, :local_demand_path_for!, :local_exists?, :remote_fetch, :logger, to: :arena
delegate :generate_for, to: :derivative
# @api private
def call
logger.debug("Starting processing #{arena.manifest.id} for derivative #{derivative.inspect}")
local_exists?(derivative: derivative) ||
remote_fetch(derivative: derivative) ||
generate_for(arena: arena)
# Will raise an exception if the above failed to put the derivative in the correct local
# location.
local_demand_path_for!(derivative: derivative)
logger.debug("Completed processing #{arena.manifest.id} for derivative #{derivative.inspect}")
process_next_chain_link_after!(derivative: derivative)
end
end
end
end