Class: Restspec::Schema::AttributeExample

Inherits:
Object
  • Object
show all
Defined in:
lib/restspec/schema/attribute_example.rb

Overview

Generates an example for a single attribute.

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ AttributeExample



8
9
10
# File 'lib/restspec/schema/attribute_example.rb', line 8

def initialize(attribute)
  self.attribute = attribute
end

Instance Method Details

#value#as_json

Generates an example using the hardcoded example_override option in the attribute or by calling the #example_for method of the type.

Returns:

  • (#as_json)

    the generated example attribute.



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

def value
  if attribute.example.present?
    attribute.example.try(:call) || attribute.example
  else
    type.example_for(attribute)
  end
end