Class: Heroics::Schema
- Inherits:
-
Object
- Object
- Heroics::Schema
- Defined in:
- lib/heroics/schema.rb
Overview
A wrapper around a bare JSON schema to make it easier to use.
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#description ⇒ Object
A description of the API.
-
#initialize(schema) ⇒ Schema
constructor
Instantiate a schema.
-
#inspect ⇒ Object
(also: #to_s)
Get a simple human-readable representation of this client instance.
-
#resource(name) ⇒ Object
Get a schema for a named resource.
-
#resources ⇒ Array<ResourceSchema>
The resource schema children that are part of this schema.
Constructor Details
#initialize(schema) ⇒ Schema
Instantiate a schema.
10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/heroics/schema.rb', line 5 def schema @schema end |
Instance Method Details
#description ⇒ Object
A description of the API.
19 20 21 |
# File 'lib/heroics/schema.rb', line 19 def description @schema['description'] end |
#inspect ⇒ Object Also known as: to_s
Get a simple human-readable representation of this client instance.
43 44 45 |
# File 'lib/heroics/schema.rb', line 43 def inspect "#<Heroics::Schema description=\"#{@schema['description']}\">" end |
#resource(name) ⇒ Object
Get a schema for a named resource.
27 28 29 30 31 32 33 |
# 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 ⇒ Array<ResourceSchema>
The resource schema children that are part of this schema.
38 39 40 |
# File 'lib/heroics/schema.rb', line 38 def resources @resources.values end |