class Patchboard::SchemaManager
Public Class Methods
new(schemas)
click to toggle source
# File lib/patchboard/schema_manager.rb, line 5 def initialize(schemas) @schemas = schemas @media_types = {} @ids = {} @names = {} @schemas.each do |schema| # TODO error checking for missing id base_id = schema[:id].chomp("#") schema[:definitions].each do |name, definition| # `definitions` is the conventional place to put schemas, # so we'll define fragment IDs by default where they are # not explicitly specified. id = definition[:id] || [base_id, name].join("#") self.register_schema(id, definition) end end end
Public Instance Methods
find(options)
click to toggle source
# File lib/patchboard/schema_manager.rb, line 35 def find(options) if type = options[:mediaType] || options[:media_type] @media_types[type] elsif ref = options[:ref] @ids[ref] elsif name = options[:name] @names[name] else raise "Unusable argument to find: #{options}" end end
register_schema(id, schema)
click to toggle source
# File lib/patchboard/schema_manager.rb, line 24 def register_schema(id, schema) # FIXME: extensions and refs are not imported. schema[:id] = id @ids[id] = schema name = id.split("#")[1].to_sym @names[name] = schema if type = schema[:mediaType] @media_types[type] = schema end end