Class: GrapeSwagger::DocMethods::OptionalObject

Inherits:
Object
  • Object
show all
Defined in:
lib/grape-swagger/doc_methods/optional_object.rb

Class Method Summary collapse

Class Method Details

.build(key, options, request = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/grape-swagger/doc_methods/optional_object.rb', line 7

def build(key, options, request = nil)
  if options[key]
    return evaluate(key, options, request) if options[key].is_a?(Proc)

    options[key]
  else
    request.send(default_values[key])
  end
end

.default_valuesObject



21
22
23
24
25
26
# File 'lib/grape-swagger/doc_methods/optional_object.rb', line 21

def default_values
  {
    host: 'host_with_port',
    base_path: 'script_name'
  }
end

.evaluate(key, options, request) ⇒ Object



17
18
19
# File 'lib/grape-swagger/doc_methods/optional_object.rb', line 17

def evaluate(key, options, request)
  options[key].arity.zero? ? options[key].call : options[key].call(request)
end