Class: Capsium::Package::RouteTarget

Inherits:
Shale::Mapper
  • Object
show all
Defined in:
lib/capsium/package/routes_config.rb

Instance Method Summary collapse

Instance Method Details

#fs_path(manifest) ⇒ Object



11
12
13
14
15
# File 'lib/capsium/package/routes_config.rb', line 11

def fs_path(manifest)
  return unless file

  manifest.path_to_content_file(manifest.lookup(file)&.file)
end

#mime(manifest) ⇒ Object



17
18
19
# File 'lib/capsium/package/routes_config.rb', line 17

def mime(manifest)
  manifest.lookup(file)&.mime
end

#validate(manifest, storage) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/capsium/package/routes_config.rb', line 21

def validate(manifest, storage)
  if file
    target_path = fs_path(manifest)
    unless target_path && File.exist?(target_path) && target_path.to_s.start_with?(manifest.content_path.to_s)
      raise "Route target does not exist or is outside of the content directory: #{target_path}"
    end
  elsif dataset
    unless storage.datasets.any? { |ds| ds.config.name == dataset }
      raise "Dataset target does not exist: #{dataset}"
    end
  else
    raise "Route target must have either a file or a dataset"
  end
end