Class: Restspec::Schema::SchemaExample
- Inherits:
-
Object
- Object
- Restspec::Schema::SchemaExample
- Defined in:
- lib/restspec/schema/schema_example.rb
Overview
A value object that generates a example from a schema using an optional set of extensions.
Instance Attribute Summary collapse
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema, extensions = {}) ⇒ SchemaExample
constructor
A new instance of SchemaExample.
-
#value ⇒ Restspec::Values::SuperHash
It returns the generated example.
Constructor Details
#initialize(schema, extensions = {}) ⇒ SchemaExample
Returns a new instance of SchemaExample.
10 11 12 13 |
# File 'lib/restspec/schema/schema_example.rb', line 10 def initialize(schema, extensions = {}) self.schema = schema self.extensions = extensions end |
Instance Attribute Details
#extensions ⇒ Object
Returns the value of attribute extensions.
6 7 8 |
# File 'lib/restspec/schema/schema_example.rb', line 6 def extensions @extensions end |
#schema ⇒ Object
Returns the value of attribute schema.
5 6 7 |
# File 'lib/restspec/schema/schema_example.rb', line 5 def schema @schema end |
Instance Method Details
#value ⇒ Restspec::Values::SuperHash
It returns the generated example.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/restspec/schema/schema_example.rb', line 17 def value example_attributes = attributes.inject({}) do |sample, (_, attribute)| sample.merge(attribute.name => AttributeExample.new(attribute).value) end.merge(extensions) if schema.root? wrap_in_root(example_attributes) else example_attributes end end |