Class: RspecApiDocumentation::DSL::Endpoint::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_documentation/dsl/endpoint/params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example_group, example, extra_params) ⇒ Params

Returns a new instance of Params.



9
10
11
12
13
# 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

Instance Attribute Details

#exampleObject (readonly)

Returns the value of attribute example.



7
8
9
# File 'lib/rspec_api_documentation/dsl/endpoint/params.rb', line 7

def example
  @example
end

#example_groupObject (readonly)

Returns the value of attribute example_group.



7
8
9
# File 'lib/rspec_api_documentation/dsl/endpoint/params.rb', line 7

def example_group
  @example_group
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/rspec_api_documentation/dsl/endpoint/params.rb', line 15

def call
  set_param = -> hash, param {
    SetParam.new(self, hash, param).call
  }

  example..fetch(:parameters, {}).inject({}, &set_param)
    .deep_merge(
      example..fetch(:attributes, {}).inject({}, &set_param)
    ).deep_merge(extra_params)
end

#extendedObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rspec_api_documentation/dsl/endpoint/params.rb', line 26

def extended
  example..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