Module: Upkeep::SharedStreams
- Defined in:
- lib/upkeep/shared_streams.rb
Constant Summary collapse
- PREFIX =
"upkeep:shared"
Class Method Summary collapse
- .identity_signature_for(graph, frame_id) ⇒ Object
- .names_for_graph(graph) ⇒ Object
- .names_for_recorder(recorder) ⇒ Object
- .names_for_subscription(subscription) ⇒ Object
- .signature_for(recipe) ⇒ Object
- .stream_name(target:, identity_signature:, sharing_signature:) ⇒ Object
- .target_for_frame(frame) ⇒ Object
Class Method Details
.identity_signature_for(graph, frame_id) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/upkeep/shared_streams.rb', line 55 def identity_signature_for(graph, frame_id) identity_dependencies = graph.contained_node_ids(frame_id) .flat_map { |owner_id| graph.dependencies_for(owner_id) } .select(&:identity?) .uniq(&:cache_key) return "public" if identity_dependencies.empty? Digest::SHA256.hexdigest(identity_dependencies.map(&:identity_key).sort_by(&:inspect).inspect)[0, 16] end |
.names_for_graph(graph) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/upkeep/shared_streams.rb', line 34 def names_for_graph(graph) graph.frame_nodes.filter_map do |frame| next unless frame.payload.fetch(:kind) == "render_site" recipe = frame.payload[:recipe] next unless recipe identity_signature = identity_signature_for(graph, frame.id) next unless identity_signature == "public" target = target_for_frame(frame) next unless target stream_name( target: target, identity_signature: identity_signature, sharing_signature: signature_for(recipe) ) end.uniq.sort end |
.names_for_recorder(recorder) ⇒ Object
30 31 32 |
# File 'lib/upkeep/shared_streams.rb', line 30 def names_for_recorder(recorder) names_for_graph(recorder.graph) end |
.names_for_subscription(subscription) ⇒ Object
26 27 28 |
# File 'lib/upkeep/shared_streams.rb', line 26 def names_for_subscription(subscription) names_for_graph(subscription.graph) end |
.signature_for(recipe) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/upkeep/shared_streams.rb', line 16 def signature_for(recipe) if recipe.instance_variable_defined?(:@upkeep_shared_stream_signature) recipe.instance_variable_get(:@upkeep_shared_stream_signature) else Digest::SHA256.hexdigest(recipe.to_h.inspect).tap do |signature| recipe.instance_variable_set(:@upkeep_shared_stream_signature, signature) end end end |
.stream_name(target:, identity_signature:, sharing_signature:) ⇒ Object
11 12 13 14 |
# File 'lib/upkeep/shared_streams.rb', line 11 def stream_name(target:, identity_signature:, sharing_signature:) digest = Digest::SHA256.hexdigest([target.kind, target.id, identity_signature, sharing_signature].inspect)[0, 32] "#{PREFIX}:#{digest}" end |