Class: Heroics::ResourceSchema
- Inherits:
-
Object
- Object
- Heroics::ResourceSchema
- Defined in:
- lib/heroics/schema.rb
Overview
A wrapper around a bare resource element in a JSON schema to make it easier to use.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#description ⇒ Object
A description of the resource.
-
#initialize(schema, name) ⇒ ResourceSchema
constructor
Instantiate a resource schema.
-
#link(name) ⇒ Object
Get a schema for a named link.
-
#links ⇒ Array<LinkSchema>
The link schema children that are part of this resource schema.
Constructor Details
#initialize(schema, name) ⇒ ResourceSchema
Instantiate a resource schema.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/heroics/schema.rb', line 58 def initialize(schema, name) @schema = schema @name = name link_schema = schema['definitions'][name]['links'] || [] @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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
52 53 54 |
# File 'lib/heroics/schema.rb', line 52 def name @name end |
Instance Method Details
#description ⇒ Object
A description of the resource.
70 71 72 |
# File 'lib/heroics/schema.rb', line 70 def description @schema['definitions'][name]['description'] end |
#link(name) ⇒ Object
Get a schema for a named link.
78 79 80 81 82 |
# File 'lib/heroics/schema.rb', line 78 def link(name) schema = @links[name] raise SchemaError.new("Unknown link '#{name}'.") unless schema schema end |
#links ⇒ Array<LinkSchema>
The link schema children that are part of this resource schema.
87 88 89 |
# File 'lib/heroics/schema.rb', line 87 def links @links.values end |