Sha256: edce565f35f4cc93d22829720eaf6effe24e6cc8526935de9a82e3fd6bd94940

Contents?: true

Size: 627 Bytes

Versions: 4

Compression:

Stored size: 627 Bytes

Contents

module Restspec::Schema::Types
  class EmbeddedSchemaType < BasicType
    attr_accessor :schema_name

    def initialize(options, options_when_name_is_present = {})
      if options.is_a?(Symbol)
        self.schema_name = options
        super(options_when_name_is_present)
      else
        super(options)
      end
    end

    def example_for(attribute)
      Restspec::Schema::SchemaExample.new(schema).value
    end

    def valid?(attribute, value)
      Restspec::Schema::Checker.new(schema).check!(value)
    end

    private

    def schema
      @schema ||= Restspec::SchemaStore.get(schema_name)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
restspec-0.0.4 lib/restspec/schema/types/embedded_schema_type.rb
restspec-0.0.3 lib/restspec/schema/types/embedded_schema_type.rb
restspec-0.0.2 lib/restspec/schema/types/embedded_schema_type.rb
restspec-0.0.1 lib/restspec/schema/types/embedded_schema_type.rb