class Capsium::Package::Routes
Constants
- DATASET_ROUTE_PREFIX
- INDEX_RESOURCE
- INDEX_ROUTE
Attributes
path
[R]
String
Public Class Methods
# File lib/capsium/package/routes.rb, line 18 def initialize(path, manifest, storage) @path = path @manifest = manifest @storage = storage @config = if File.exist?(path) RoutesConfig.from_json(File.read(path)) else generate_routes end end
Public Instance Methods
(String route, String target) → Route
Source
# File lib/capsium/package/routes.rb, line 33 def add_route(route, target) @config.add(route, target) end
Source
# File lib/capsium/package/routes.rb, line 58 def generate_routes routes = resource_routes + dataset_routes RoutesConfig.new(index: index_resource, routes: routes.sort_by(&:path)) end
Auto-generation (ARCHITECTURE.md section 4): every manifest resource gets a route at its path relative to content/; HTML files get two routes (basename without extension and full filename); the index HTML additionally gets “/”; every dataset in storage gets /api/v1/data/<id>. Output is deterministic (sorted by path).
(String route) → Array[Route]
Source
# File lib/capsium/package/routes.rb, line 41 def remove_route(route) @config.remove(route) end
(String url_path) → Route?
Source
# File lib/capsium/package/routes.rb, line 29 def resolve(url_path) @config.resolve(url_path) end
(?String output_path) → void
Source
# File lib/capsium/package/routes.rb, line 49 def save_to_file(output_path = @path) File.write(output_path, to_json) end
(*untyped args) → String
Source
# File lib/capsium/package/routes.rb, line 45 def to_json(*_args) @config.to_json end
(String route, String updated_route, String updated_target) → Route
Source
# File lib/capsium/package/routes.rb, line 37 def update_route(route, updated_route, updated_target) @config.update(route, updated_route, updated_target) end