Class: Meta::RouteDSL::UniformedParamsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/meta/route_dsl/uniformed_params_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(route_full_path:, route_method:, &block) ⇒ UniformedParamsBuilder

Returns a new instance of UniformedParamsBuilder.



6
7
8
9
10
11
12
13
14
# File 'lib/meta/route_dsl/uniformed_params_builder.rb', line 6

def initialize(route_full_path:, route_method:, &block)
  @route_full_path = route_full_path
  @route_method = route_method
  @parameters_builder = ParametersBuilder.new(route_full_path: @route_full_path, route_method: @route_method)

  @parameter_options = {}

  instance_exec &block if block_given?
end

Instance Method Details

#buildObject



39
40
41
# File 'lib/meta/route_dsl/uniformed_params_builder.rb', line 39

def build
  [@parameters_builder.build, @request_body_builder&.to_schema]
end

#param(name, options = {}, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/meta/route_dsl/uniformed_params_builder.rb', line 16

def param(name, options = {}, &block)
  options = (options || {}).dup
    if path_param_names.include?(name)
      options = Utils::Kwargs::Helpers.fix!(options, in: 'path', required: true)
    elsif @route_method == :get
      options = Utils::Kwargs::Helpers.merge_defaults!(options, in: 'query')
    else
      options = Utils::Kwargs::Helpers.merge_defaults!(options, in: 'body')
    end

  if options[:in] == 'body'
    options.delete(:in)
    property name, options, &block
  else
    @parameters_builder.param name, options
  end
end

#property(name, options = {}, &block) ⇒ Object



34
35
36
37
# File 'lib/meta/route_dsl/uniformed_params_builder.rb', line 34

def property(name, options = {}, &block)
  @request_body_builder ||= JsonSchema::ObjectSchemaBuilder.new
  @request_body_builder.property name, options, &block
end