class Interface::DefaultAdapter
Attributes
callable[R]
Public Class Methods
new(callable)
click to toggle source
# File lib/interface/default_adapter.rb, line 6 def initialize(callable) @callable = callable end
Public Instance Methods
call(*args, &block)
click to toggle source
# File lib/interface/default_adapter.rb, line 10 def call(*args, &block) _call(*args, &block) end
Private Instance Methods
_call(*args, &block)
click to toggle source
# File lib/interface/default_adapter.rb, line 18 def _call(*args, &block) status, _result = _handle_request(*args, &block) # Response.__ok__(_result) # Response.__error__(_result) Response.public_send("__#{status}__", _result) end
_handle_request(*args, &block)
click to toggle source
# File lib/interface/default_adapter.rb, line 26 def _handle_request(*args, &block) if callable.respond_to?(:dispatch) _wrap(callable.dispatch(*args, &block)) elsif callable.respond_to?(:call) _wrap(callable.call(*args, &block)) else fail(Interface::Errors::AdaptationError.new("#{callable.class} is not callable!")) end rescue => e [:error, e] end
_wrap(result)
click to toggle source
# File lib/interface/default_adapter.rb, line 38 def _wrap(result) return [:ok, result] unless result.is_a?(Array) status, _result = result status == :ok ? [:ok, _result] : [:error, _result] end