Module: RailsWayback::RenderProvenance

Defined in:
lib/rails_wayback/render_provenance.rb

Overview

Classifies Action View render identifiers by filesystem origin and normalizes them back to paths relative to the host application. Both the engine logger and toolbar use this module so they cannot drift into applying different provenance rules.

Class Method Summary collapse

Class Method Details

.origin_for(identifier, configuration: RailsWayback.configuration) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/rails_wayback/render_provenance.rb', line 13

def origin_for(identifier, configuration: RailsWayback.configuration)
  path = absolute_path(identifier)
  return :other unless path

  refs_root = File.expand_path(configuration.refs_cache_path.to_s)
  return :historical if under?(path, refs_root)
  return :current if current_view_roots(configuration).any? { |root| under?(path, root) }

  :other
end

.paths_by_origin(entries, configuration: RailsWayback.configuration) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails_wayback/render_provenance.rb', line 24

def paths_by_origin(entries, configuration: RailsWayback.configuration)
  result = { historical: [], current: [] }

  Array(entries).each do |entry|
    identifier = identifier_from(entry)
    origin = origin_for(identifier, configuration: configuration)
    next unless result.key?(origin)

    relative = relative_path(identifier, origin, configuration)
    result[origin] << relative if relative
  end

  result.transform_values(&:uniq)
end