Sha256: d6c35eacef6adda9a902f9caa864e0dee3c83558872d9c43da63eccd9cf339fd

Contents?: true

Size: 929 Bytes

Versions: 6

Compression:

Stored size: 929 Bytes

Contents

# frozen_string_literal: true

require 'modern/dsl/info'
require 'modern/dsl/scope'

module Modern
  module DSL
    class Root < Scope
      attr_reader :descriptor

      def initialize(descriptor)
        super(descriptor, nil)
      end

      def info(&block)
        @descriptor = @descriptor.copy(
          info: Info.build(descriptor.info.title, descriptor.info.version, &block).to_h
        )
      end

      def server(url, description: nil)
        raise "url is required for a server declaration." if url.nil?

        @descriptor = @descriptor.copy(
          servers: @descriptor.servers + [Modern::Descriptor::Server.new(url: url, description: description)]
        )
      end

      def self.build(title, version, &block)
        d = Modern::Descriptor::Core.new(info: { title: title, version: version })

        r = Root.new(d)
        r.instance_exec(&block)
        r.descriptor
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
modern-0.5.0 lib/modern/dsl/root.rb
modern-0.4.6 lib/modern/dsl/root.rb
modern-0.4.5 lib/modern/dsl/root.rb
modern-0.4.4 lib/modern/dsl/root.rb
modern-0.4.3 lib/modern/dsl/root.rb
modern-0.4.2 lib/modern/dsl/root.rb