class RspecApiDocumentation::DSL::Endpoint::Params

Attributes

example[R]
example_group[R]
extra_params[R]

Public Class Methods

new(example_group, example, extra_params) click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/params.rb, line 9
def initialize(example_group, example, extra_params)
  @example_group = example_group
  @example = example
  @extra_params = extra_params
end

Public Instance Methods

call() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/params.rb, line 15
def call
  set_param = -> hash, param {
    SetParam.new(self, hash, param).call
  }

  example.metadata.fetch(:parameters, {}).inject({}, &set_param)
    .deep_merge(
      example.metadata.fetch(:attributes, {}).inject({}, &set_param)
    ).deep_merge(extra_params)
end
extended() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/params.rb, line 26
def extended
  example.metadata.fetch(:parameters, {}).map do |param|
    p = Marshal.load(Marshal.dump(param))
    p[:value] = SetParam.new(self, nil, p).value
    unless p[:value]
      cur = extra_params
      [*p[:scope]].each { |scope| cur = cur && (cur[scope.to_sym] || cur[scope.to_s]) }
      p[:value] = cur && (cur[p[:name].to_s] || cur[p[:name].to_sym])
    end
    p
  end
end