Class: Restspec::Schema::SchemaExample

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(schema, extensions = {}) ⇒ 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

#extensionsObject

Returns the value of attribute extensions


6
7
8
# File 'lib/restspec/schema/schema_example.rb', line 6

def extensions
  @extensions
end

#schemaObject

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

#valueRestspec::Values::SuperHash

It returns the generated example.


17
18
19
20
21
# File 'lib/restspec/schema/schema_example.rb', line 17

def value
  attributes.inject({}) do |sample, (_, attribute)|
    sample.merge(attribute.name => AttributeExample.new(attribute).value)
  end.merge(extensions)
end