Module: JSONSchemer::Location

Defined in:
lib/json_schemer/location.rb

Constant Summary collapse

JSON_POINTER_TOKEN_ESCAPE_CHARS =
{ '~' => '~0', '/' => '~1' }
JSON_POINTER_TOKEN_ESCAPE_REGEX =
Regexp.union(JSON_POINTER_TOKEN_ESCAPE_CHARS.keys)

Class Method Summary collapse

Class Method Details

.escape_json_pointer_token(token) ⇒ Object



20
21
22
# File 'lib/json_schemer/location.rb', line 20

def escape_json_pointer_token(token)
  token.gsub(JSON_POINTER_TOKEN_ESCAPE_REGEX, JSON_POINTER_TOKEN_ESCAPE_CHARS)
end

.join(location, name) ⇒ Object



12
13
14
# File 'lib/json_schemer/location.rb', line 12

def join(location, name)
  location[name] ||= { :name => name, :parent => location }
end

.resolve(location) ⇒ Object



16
17
18
# File 'lib/json_schemer/location.rb', line 16

def resolve(location)
  location[:resolve] ||= location[:parent] ? "#{resolve(location[:parent])}/#{escape_json_pointer_token(location[:name])}" : ''
end

.rootObject



8
9
10
# File 'lib/json_schemer/location.rb', line 8

def root
  {}
end