class Heroics::Schema
A wrapper around a bare JSON schema to make it easier to use.
Attributes
schema[R]
Public Class Methods
new(schema)
click to toggle source
Instantiate a schema.
@param schema [Hash] The bare JSON schema to wrap.
# File lib/heroics/schema.rb, line 10 def initialize(schema) @schema = schema @resources = {} @schema['properties'].each do |key, value| @resources[key] = ResourceSchema.new(@schema, key) end end
Public Instance Methods
description()
click to toggle source
A description of the API.
# File lib/heroics/schema.rb, line 19 def description @schema['description'] end
inspect()
click to toggle source
Get a simple human-readable representation of this client instance.
# File lib/heroics/schema.rb, line 43 def inspect "#<Heroics::Schema description=\"#{@schema['description']}\">" end
Also aliased as: to_s
resource(name)
click to toggle source
Get a schema for a named resource.
@param name [String] The name of the resource. @raise [SchemaError] Raised if an unknown resource name is provided.
# File lib/heroics/schema.rb, line 27 def resource(name) if @schema['definitions'].has_key?(name) ResourceSchema.new(@schema, name) else raise SchemaError.new("Unknown resource '#{name}'.") end end
resources()
click to toggle source
The resource schema children that are part of this schema.
@return [Array<ResourceSchema>] The resource schema children.
# File lib/heroics/schema.rb, line 38 def resources @resources.values end