Class: Dhall::Import::URI
- Inherits:
-
Object
- Object
- Dhall::Import::URI
- Defined in:
- lib/dhall/ast.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #canonical ⇒ Object
- #chain_onto(relative_to) ⇒ Object
- #headers ⇒ Object
-
#initialize(headers, authority, *path, query) ⇒ URI
constructor
A new instance of URI.
- #origin ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
- #with(hash) ⇒ Object
Constructor Details
#initialize(headers, authority, *path, query) ⇒ URI
Returns a new instance of URI.
1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'lib/dhall/ast.rb', line 1231 def initialize(headers, , *path, query) super( headers: headers, authority: , path: path, query: query, ) end |
Class Method Details
.from_uri(uri) ⇒ Object
1249 1250 1251 1252 1253 1254 1255 1256 1257 |
# File 'lib/dhall/ast.rb', line 1249 def self.from_uri(uri) (uri.scheme == "https" ? Https : Http).new( nil, "#{uri.host}:#{uri.port}", *uri.path.split(/\//)[1..-1], uri.query, nil ) end |
Instance Method Details
#as_json ⇒ Object
1302 1303 1304 |
# File 'lib/dhall/ast.rb', line 1302 def as_json [@headers&.as_json, , *path, query] end |
#canonical ⇒ Object
1285 1286 1287 1288 1289 1290 1291 1292 |
# File 'lib/dhall/ast.rb', line 1285 def canonical with( path: (path[1..-1] + [""]) .reduce([[], path.first]) { |(pth, prev), c| c == ".." ? [pth, prev] : [pth + [prev], c] }.first.reject { |c| c == "." } ) end |
#chain_onto(relative_to) ⇒ Object
1277 1278 1279 1280 1281 1282 1283 |
# File 'lib/dhall/ast.rb', line 1277 def chain_onto(relative_to) if headers.is_a?(Import) with(headers: headers.with(path: headers.real_path(relative_to))) else self end end |
#headers ⇒ Object
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 |
# File 'lib/dhall/ast.rb', line 1259 def headers header_type = RecordType.new( record: { "header" => Builtins[:Text], "value" => Builtins[:Text] } ) super || EmptyList.new(element_type: header_type) end |
#origin ⇒ Object
1294 1295 1296 |
# File 'lib/dhall/ast.rb', line 1294 def origin "#{scheme}://#{authority}" end |
#to_s ⇒ Object
1298 1299 1300 |
# File 'lib/dhall/ast.rb', line 1298 def to_s uri.to_s end |
#uri ⇒ Object
1270 1271 1272 1273 1274 1275 |
# File 'lib/dhall/ast.rb', line 1270 def uri escaped_path = path.map do |c| ::URI.encode_www_form_component(c).gsub("+", "%20") end URI("#{scheme}://#{authority}/#{escaped_path.join("/")}?#{query}") end |
#with(hash) ⇒ Object
1240 1241 1242 1243 1244 1245 1246 1247 |
# File 'lib/dhall/ast.rb', line 1240 def with(hash) self.class.new( hash.fetch(:headers, headers), hash.fetch(:authority, ), *hash.fetch(:path, path), hash.fetch(:query, query) ) end |