Sha256: 6251ae651c5349b286a791151591c65daf8d0c92c7c1090a27a29519a77bcc8b

Contents?: true

Size: 771 Bytes

Versions: 2

Compression:

Stored size: 771 Bytes

Contents

module Restspec
  module Schema
    class DSL
      attr_reader :schemas

      def schema(name, &definition)
        dsl = SingleSchemaDSL.new(name)
        dsl.instance_eval(&definition)
        Restspec::SchemaStore.store(dsl.schema)
      end
    end

    class SingleSchemaDSL
      attr_reader :schema

      def initialize(name)
        self.schema = Schema.new(name)
      end

      def attribute(name, type, options = {})
        new_attribute = Attribute.new(name, type, options)
        schema.attributes[name.to_s] = new_attribute
      end

      Types::ALL.each do |type_name, type_class|
        define_method(type_name) do |options = {}|
          type_class.new(options)
        end
      end

      private

      attr_writer :schema
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restspec-0.0.2 lib/restspec/schema/dsl.rb
restspec-0.0.1 lib/restspec/schema/dsl.rb