class Restspec::Schema::AttributeExample

Generates an example for a single attribute.

Attributes

attribute[RW]

Public Class Methods

new(attribute) click to toggle source

Creates a new {AttributeExample} with an {Attribute} object.

# File lib/restspec/schema/attribute_example.rb, line 8
def initialize(attribute)
  self.attribute = attribute
end

Public Instance Methods

value() click to toggle source

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

@return [#as_json] the generated example attribute.

# 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

Private Instance Methods

type() click to toggle source
# File lib/restspec/schema/attribute_example.rb, line 28
def type
  attribute.type
end