class Capsium::Package::RoutesConfig
Canonical routes.json model: optional top-level โindexโ plus a โroutesโ array. The legacy gem form ({path, target: {file|dataset}}) is accepted on read and normalized; writers emit only the canonical form.
Public Class Methods
(String json) → instance
Source
# File lib/capsium/package/routes_config.rb, line 152 def self.from_json(json) doc = JSON.parse(json) doc["routes"] = (doc["routes"] || []).map { |route| normalize_route(route) } super(JSON.generate(doc)) end
Calls superclass method
Public Instance Methods
(String path, String target) → Route
Source
# File lib/capsium/package/routes_config.rb, line 181 def add(path, target) route = Route.new(path: path, resource: target) self.routes = routes + [route] route end
(String path) → Array[Route]
Source
# File lib/capsium/package/routes_config.rb, line 194 def remove(path) self.routes = routes.reject { |route| route.path == path } end
(String path) → Route?
Source
# File lib/capsium/package/routes_config.rb, line 177 def resolve(path) routes.detect { |route| route.serving_path == path } end
(RoutesConfig model, untyped value) → void
Source
# File lib/capsium/package/routes_config.rb, line 166 def routes_from_json(model, value) model.routes = (value || []).map { |route| Route.from_json(JSON.generate(route)) } end
(RoutesConfig model, Hash[String, untyped] doc) → void
Source
# File lib/capsium/package/routes_config.rb, line 171 def routes_to_json(model, doc) doc["routes"] = model.routes.sort_by(&:path).map do |route| JSON.parse(route.to_json) end end
Writers emit the canonical form only: deterministic, sorted by path.
() → RoutesConfig
Source
# File lib/capsium/package/routes_config.rb, line 198 def sort! self.routes = routes.sort_by(&:path) self end
(String path, String updated_path, String updated_target) → Route
Source
# File lib/capsium/package/routes_config.rb, line 187 def update(path, updated_path, updated_target) route = resolve(path) route.path = updated_path route.resource = updated_target route end