class JSchema::SchemaURI
Public Class Methods
build(schema_id, parent_schema, id)
click to toggle source
String, Schema
, String
# File lib/jschema/schema_uri.rb, line 7 def build(schema_id, parent_schema, id) # RFC 3986, cl. 5.1 if parent_schema if parent_schema.uri.absolute? new_uri_part = schema_id || join_fragments(parent_schema.uri.fragment, id) parent_schema.uri.merge(new_uri_part).normalize elsif parent_schema.uri.path.empty? join_fragments(parent_schema.uri.fragment, id) else # RFC 3986, cl. 5.1.4 fail InvalidSchema, 'Cannot establish base URI' end else uri(schema_id || id || '#') end end
Private Class Methods
join_fragments(primary, secondary)
click to toggle source
# File lib/jschema/schema_uri.rb, line 28 def join_fragments(primary, secondary) uri('#' + File.join(primary || '', secondary || '')) end
uri(uri_string)
click to toggle source
# File lib/jschema/schema_uri.rb, line 32 def uri(uri_string) # NOTE: We need to escape % because URI class does not allow such # characters within URI fragment (which is wrong). Originally I used # URI.escape(str, '%'), but this method has become obsolete. escaped_uri = WEBrick::HTTPUtils._escape(uri_string, /([%])/) URI(escaped_uri) end