Sha256: f5ce97459424f14068d33f826cb86f5a2a75360cbad36843ca94945419fe712e

Contents?: true

Size: 794 Bytes

Versions: 11

Compression:

Stored size: 794 Bytes

Contents

require 'faker'

module Restspec
  module Schema
    # 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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
restspec-0.3.2 lib/restspec/schema/attribute_example.rb
restspec-0.3.1 lib/restspec/schema/attribute_example.rb
restspec-0.3.0 lib/restspec/schema/attribute_example.rb
restspec-0.2.6 lib/restspec/schema/attribute_example.rb
restspec-0.2.5 lib/restspec/schema/attribute_example.rb
restspec-0.2.4 lib/restspec/schema/attribute_example.rb
restspec-0.2.3 lib/restspec/schema/attribute_example.rb
restspec-0.2.2 lib/restspec/schema/attribute_example.rb
restspec-0.2.1 lib/restspec/schema/attribute_example.rb
restspec-0.2 lib/restspec/schema/attribute_example.rb
restspec-0.1 lib/restspec/schema/attribute_example.rb