Class: Restspec::Schema::AttributeExample
- Inherits:
-
Object
- Object
- Restspec::Schema::AttributeExample
- Defined in:
- lib/restspec/schema/attribute_example.rb
Overview
Generates an example for a single attribute.
Instance Method Summary collapse
-
#initialize(attribute) ⇒ AttributeExample
constructor
Creates a new AttributeExample with an Attribute object.
-
#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.
Constructor Details
#initialize(attribute) ⇒ AttributeExample
Creates a new Restspec::Schema::AttributeExample with an Restspec::Schema::Attribute object.
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.
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 |