Class: StubRequests::Callback

Inherits:
Object
  • Object
show all
Includes:
StubRequests::Concerns::Property
Defined in:
lib/stub_requests/callback.rb

Overview

Class Callback contains information about a subscription

Author:

Since:

  • 0.1.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StubRequests::Concerns::Property

included

Methods included from StubRequests::Concerns::ArgumentValidation

#validate!, #validate_type!

Constructor Details

#initialize(service_id, endpoint_id, verb, callback) ⇒ Callback

Initialize a new Callback

Parameters:

  • service_id (Symbol)

    the id of a service

  • endpoint_id (Symbol)

    the id of an endpoint

  • verb (Symbol)

    the HTTP verb/method

  • callback (Proc)

    a proc to callback on notify

Since:

  • 0.1.3



45
46
47
48
49
50
# File 'lib/stub_requests/callback.rb', line 45

def initialize(service_id, endpoint_id, verb, callback)
  self.service_id  = service_id
  self.endpoint_id = endpoint_id
  self.verb        = verb
  self.callback    = callback
end

Instance Attribute Details

#callbackProc

Returns a proc to callback on notify

Returns:

  • (Proc)

    a proc to callback on notify



35
# File 'lib/stub_requests/callback.rb', line 35

property :callback, type: Proc

#endpoint_idSymbol

Returns the id of an endpoint

Returns:

  • (Symbol)

    the id of an endpoint



27
# File 'lib/stub_requests/callback.rb', line 27

property :endpoint_id, type: Symbol

#service_idSymbol

Returns the id of a service

Returns:

  • (Symbol)

    the id of a service



23
# File 'lib/stub_requests/callback.rb', line 23

property :service_id, type: Symbol

#verbSymbol

Returns the HTTP verb/method

Returns:

  • (Symbol)

    the HTTP verb/method



31
# File 'lib/stub_requests/callback.rb', line 31

property :verb, type: Symbol, default: :any

Instance Method Details

#arityObject

Since:

  • 0.1.3



63
64
65
# File 'lib/stub_requests/callback.rb', line 63

def arity
  callback.arity
end

#call(request_stub) ⇒ Object

Since:

  • 0.1.3



52
53
54
55
56
57
58
59
60
61
# File 'lib/stub_requests/callback.rb', line 52

def call(request_stub)
  case arity
  when 0
    callback.call
  when 1
    callback.call(request_stub)
  else
    raise InvalidCallback, "The callback for a callback can either take 0 or 1 arguments (was #{arity})"
  end
end