Sha256: 3a59f0d97184f1623b1ef81241e983256cc483b5e640beaa9e24eaa94a722084

Contents?: true

Size: 761 Bytes

Versions: 25

Compression:

Stored size: 761 Bytes

Contents

module Schemacop
  module V3
    class Context
      attr_accessor :schemas
      attr_accessor :json_format

      DEFAULT_JSON_FORMAT = :default

      def initialize(json_format: DEFAULT_JSON_FORMAT)
        @schemas = {}.with_indifferent_access.freeze
        @json_format = json_format
      end

      def schema(name, type = :hash, **options, &block)
        @schemas = @schemas.merge(
          name => Node.create(type, **options, &block)
        ).freeze
      end

      def with_json_format(json_format)
        prev_json_format = @json_format
        @json_format = json_format
        return yield
      ensure
        @json_format = prev_json_format
      end

      def swagger_json?
        @json_format == :swagger
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
schemacop-3.0.10 lib/schemacop/v3/context.rb
schemacop-3.0.9 lib/schemacop/v3/context.rb
schemacop-3.0.8 lib/schemacop/v3/context.rb
schemacop-3.0.7 lib/schemacop/v3/context.rb
schemacop-3.0.6 lib/schemacop/v3/context.rb