Class: GrapeSwagger::TokenOwnerResolver

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

Constant Summary collapse

SUPPORTED_ARITY_TYPES =
i[req opt rest keyreq key keyrest].freeze

Class Method Summary collapse

Class Method Details

.evaluate_proc(callable, token_owner) ⇒ Object



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

def evaluate_proc(callable, token_owner)
  return callable.call unless accepts_argument?(callable)

  callable.call(token_owner)
end

.resolve(endpoint, method_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/grape-swagger/token_owner_resolver.rb', line 10

def resolve(endpoint, method_name)
  return if method_name.nil?

  method_name = method_name.to_sym
  return endpoint.public_send(method_name) if endpoint.respond_to?(method_name, true)

  helper_value = resolve_from_helpers(endpoint, method_name)
  return helper_value unless helper_value.equal?(UNRESOLVED)

  raise Errors::TokenOwnerNotFound, "undefined method `#{method_name}` for #{endpoint.class}"
end