Module: Axn::Webhooks::Resolvers

Defined in:
lib/axn/webhooks/resolvers.rb

Class Method Summary collapse

Class Method Details

.deferred?(value) ⇒ Boolean

Resolve a declared value against the request:

Resolver -> call(request); Symbol -> request.public_send(sym);
Proc -> call(request) (or call for a 0-arity proc); else the literal.

Exactly the shapes resolve below defers — the single source of truth for "is this resolved per request, or used as a literal?". Boot-time secret checks ask this rather than respond_to?(:call): a credential-provider object or a Method responds to #call but is NOT resolved here, so exempting it from validation let it declare cleanly and then fail every request with a type error instead of failing loudly at boot (Codex review).

Returns:

  • (Boolean)


31
# File 'lib/axn/webhooks/resolvers.rb', line 31

def deferred?(value) = value.is_a?(Resolver) || value.is_a?(Symbol) || value.is_a?(Proc)

.header(name) ⇒ Object



18
# File 'lib/axn/webhooks/resolvers.rb', line 18

def header(name) = Resolver.new { |req| req.header(name) }

.paramsObject



20
# File 'lib/axn/webhooks/resolvers.rb', line 20

def params       = Resolver.new(&:params)

.raw_bodyObject



19
# File 'lib/axn/webhooks/resolvers.rb', line 19

def raw_body     = Resolver.new(&:raw_body)

.resolve(value, request) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/axn/webhooks/resolvers.rb', line 33

def resolve(value, request)
  case value
  when Resolver then value.call(request)
  when Symbol   then request.public_send(value)
  when Proc     then value.arity.zero? ? value.call : value.call(request)
  else value
  end
end

.urlObject



21
# File 'lib/axn/webhooks/resolvers.rb', line 21

def url          = Resolver.new(&:url)