class Heroics::ResourceSchema
A wrapper around a bare resource element in a JSON schema to make it easier to use.
Attributes
name[R]
Public Class Methods
new(schema, name)
click to toggle source
Instantiate a resource schema.
@param schema [Hash] The bare JSON schema to wrap. @param name [String] The name of the resource to identify in the schema.
# File lib/heroics/schema.rb, line 58 def initialize(schema, name) @schema = schema @name = name link_schema = schema['definitions'][name]['links'] || [] duplicate_names = link_schema .group_by { |link| Heroics.ruby_name(link['title']) } .select { |k, v| v.size > 1 } .map(&:first) if !duplicate_names.empty? raise SchemaError.new("Duplicate '#{name}' link names: " + "'#{duplicate_names.join("', '")}'.") end @links = Hash[link_schema.each_with_index.map do |link, link_index| link_name = Heroics.ruby_name(link['title']) [link_name, LinkSchema.new(schema, name, link_index)] end] end
Public Instance Methods
description()
click to toggle source
A description of the resource.
# File lib/heroics/schema.rb, line 79 def description @schema['definitions'][name]['description'] end
link(name)
click to toggle source
Get a schema for a named link.
@param name [String] The name of the link. @raise [SchemaError] Raised if an unknown link name is provided.
# File lib/heroics/schema.rb, line 87 def link(name) schema = @links[name] raise SchemaError.new("Unknown link '#{name}'.") unless schema schema end
links()
click to toggle source
The link schema children that are part of this resource schema.
@return [Array<LinkSchema>] The link schema children.
# File lib/heroics/schema.rb, line 96 def links @links.values end