class Restspec::Schema::SchemaExample
A value object that generates a example from a schema using an optional set of extensions.
Attributes
extensions[RW]
schema[RW]
Public Class Methods
new(schema, extensions = {})
click to toggle source
@param schema [Restspec::Schema::Schema] the schema used to generate the example. @param extensions [Hash] A set of extensions to merge with the example.
# File lib/restspec/schema/schema_example.rb, line 10 def initialize(schema, extensions = {}) self.schema = schema self.extensions = extensions end
Public Instance Methods
value()
click to toggle source
It returns the generated example. @return [Restspec::Values::SuperHash] generated example.
# 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
Private Instance Methods
attributes()
click to toggle source
# File lib/restspec/schema/schema_example.rb, line 31 def attributes schema.attributes_for_intention end
wrap_in_root(hash)
click to toggle source
# File lib/restspec/schema/schema_example.rb, line 35 def wrap_in_root(hash) { schema.root_name => hash } end