Class: Modern::DSL::Root

Inherits:
Scope
  • Object
show all
Defined in:
lib/modern/dsl/root.rb

Instance Attribute Summary collapse

Attributes inherited from Scope

#settings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Scope

#capsule, #clear_input_converters!, #clear_output_converters!, #clear_security!, #default_response, #delete, #deprecate!, evaluate, #get, #helper, #input_converter, #output_converter, #parameter, #patch, #path, #post, #put, #route, #security, #tag

Constructor Details

#initialize(descriptor) ⇒ Root

Returns a new instance of Root.



11
12
13
# File 'lib/modern/dsl/root.rb', line 11

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

Instance Attribute Details

#descriptorObject (readonly)

Returns the value of attribute descriptor.



9
10
11
# File 'lib/modern/dsl/root.rb', line 9

def descriptor
  @descriptor
end

Class Method Details

.build(title, version, &block) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/modern/dsl/root.rb', line 29

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

Instance Method Details

#info(&block) ⇒ Object



15
16
17
18
19
# File 'lib/modern/dsl/root.rb', line 15

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

#server(url, description: nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/modern/dsl/root.rb', line 21

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