lib/restspec/schema/attribute_example.rb in restspec-0.0.4 vs lib/restspec/schema/attribute_example.rb in restspec-0.1

- old
+ new

@@ -1,18 +1,30 @@ require 'faker' module Restspec module Schema - class AttributeExample < Struct.new(:attribute) + # Generates an example for a single attribute. + class AttributeExample + # Creates a new {AttributeExample} with an {Attribute} object. + def initialize(attribute) + self.attribute = attribute + end + + # 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. def value if attribute.example.present? attribute.example.try(:call) || attribute.example else type.example_for(attribute) end end private + + attr_accessor :attribute def type attribute.type end end