Class: Patchboard::SchemaManager
- Inherits:
-
Object
- Object
- Patchboard::SchemaManager
- Defined in:
- lib/patchboard/schema_manager.rb
Instance Method Summary collapse
- #find(options) ⇒ Object
-
#initialize(schemas) ⇒ SchemaManager
constructor
A new instance of SchemaManager.
- #register_schema(id, schema) ⇒ Object
Constructor Details
#initialize(schemas) ⇒ SchemaManager
Returns a new instance of SchemaManager.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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 |
Instance Method Details
#find(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/patchboard/schema_manager.rb', line 35 def find() if type = [:mediaType] || [:media_type] @media_types[type] elsif ref = [:ref] @ids[ref] elsif name = [:name] @names[name] else raise "Unusable argument to find: #{}" end end |
#register_schema(id, schema) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# 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 |