Class: Apia::DSLs::ArgumentSet

Inherits:
Apia::DSL show all
Defined in:
lib/apia/dsls/argument_set.rb

Direct Known Subclasses

LookupArgumentSet

Instance Method Summary collapse

Methods inherited from Apia::DSL

#description, #initialize, #name, #no_schema

Constructor Details

This class inherits a constructor from Apia::DSL

Instance Method Details

#argument(name, *args, type: nil, **options, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/apia/dsls/argument_set.rb', line 11

def argument(name, *args, type: nil, **options, &block)
  type = args[0] if type.nil?

  argument = Definitions::Argument.new(name, id: "#{@definition.id}/#{Helpers.camelize(name.to_s)}Argument")

  if type.is_a?(Array)
    argument.type = type[0]
    argument.array = true
  else
    argument.type = type
    argument.array = false
  end

  argument.required = options[:required] if options.key?(:required)
  argument.default = options[:default] if options.key?(:default)
  argument.description = options[:description] if options.key?(:description)

  argument.dsl.instance_eval(&block) if block_given?

  @definition.arguments[name.to_sym] = argument
end