class RspecApiDocumentation::DSL::Endpoint::SetParam

Attributes

hash[R]
param[R]
parent[R]

Public Class Methods

new(parent, hash, param) click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 5
def initialize(parent, hash, param)
  @parent = parent
  @hash = hash
  @param = param
end

Public Instance Methods

call() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 11
def call
  return hash if path_params.include?(path_name)
  return hash unless method_name

  hash.deep_merge build_param_hash(key_scope || [key])
end
value() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 18
def value
  example_group.send(method_name) if method_name
end

Private Instance Methods

build_param_hash(keys) click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 67
def build_param_hash(keys)
  value = param[:value] if param.has_key?(:value)
  value ||= keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
  { keys[0].to_s => value }
end
custom_method_name() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 39
def custom_method_name
  param[:method]
end
key() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 27
def key
  @key ||= param[:name]
end
key_scope() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 31
def key_scope
  @key_scope ||= param[:scope] && Array(param[:scope]).dup.push(key)
end
method_name() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 55
def method_name
  if custom_method_name
    custom_method_name if example_group.respond_to?(custom_method_name)
  elsif scoped_key && example_group.respond_to?(scoped_key)
    scoped_key
  elsif key && example_group.respond_to?(key)
    key
  elsif key && set_value
    key
  end
end
path_name() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 47
def path_name
  scoped_key || key
end
path_params() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 51
def path_params
  example.metadata[:route].scan(/:(\w+)/).flatten
end
scoped_key() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 35
def scoped_key
  @scoped_key ||= key_scope && key_scope.join('_')
end
set_value() click to toggle source
# File lib/rspec_api_documentation/dsl/endpoint/set_param.rb, line 43
def set_value
  param[:value]
end