Class: JSchema::SchemaURI

Inherits:
Object
  • Object
show all
Defined in:
lib/jschema/schema_uri.rb

Class Method Summary collapse

Class Method Details

.build(schema_id, parent_schema, id) ⇒ Object

String, Schema, String



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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