Class: Committee::Schema
- Inherits:
-
Object
- Object
- Committee::Schema
- Includes:
- Enumerable
- Defined in:
- lib/committee/schema.rb
Instance Method Summary collapse
- #[](type) ⇒ Object
- #each ⇒ Object
- #find(ref) ⇒ Object
-
#initialize(data) ⇒ Schema
constructor
A new instance of Schema.
Constructor Details
#initialize(data) ⇒ Schema
Returns a new instance of Schema.
5 6 7 8 9 |
# File 'lib/committee/schema.rb', line 5 def initialize(data) @cache = {} @schema = MultiJson.decode(data) manifest_regex end |
Instance Method Details
#[](type) ⇒ Object
11 12 13 |
# File 'lib/committee/schema.rb', line 11 def [](type) @schema["definitions"][type] end |
#each ⇒ Object
15 16 17 18 19 |
# File 'lib/committee/schema.rb', line 15 def each @schema["definitions"].each do |type, type_schema| yield(type, type_schema) end end |
#find(ref) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/committee/schema.rb', line 21 def find(ref) cache(ref) do parts = ref.split("/") parts.shift if parts.first == "#" pointer = @schema parts.each do |p| next unless pointer pointer = pointer[p] end raise ReferenceNotFound, "Reference not found: #{ref}." if !pointer pointer end end |