class Interface::PortEntity
Constants
- LIM
- N_A
Attributes
name[R]
Public Class Methods
new(name, adapter)
click to toggle source
# File lib/interface/port_entity.rb, line 8 def initialize(name, adapter) @name, @adapter = name, adapter end
Public Instance Methods
after_call()
click to toggle source
# File lib/interface/port_entity.rb, line 61 def after_call; end
before_call()
click to toggle source
# File lib/interface/port_entity.rb, line 60 def before_call; end
call(*args, &block)
click to toggle source
# File lib/interface/port_entity.rb, line 33 def call(*args, &block) if @handler.nil? fail(::Interface::Errors::HandlerMissingError.new("Handler is undefined")) end # if !@contract.nil? # fail(::Interface::Errors::InvalidInputError.new("Empty argument list doesn not comply with the Contract")) if args.empty? # errors = @contract.call(*args).errors # fail(::Interface::Errors::InvalidInputError.new(errors)) if errors.any? # end _callee.call(*args, &block) end
contract(&validation_schema)
click to toggle source
# File lib/interface/port_entity.rb, line 52 def contract(&validation_schema) @contract = validation_schema end
describe(text)
click to toggle source
# File lib/interface/port_entity.rb, line 12 def describe(text) @description = text end
doc()
click to toggle source
# File lib/interface/port_entity.rb, line 64 def doc puts <<-DOC #{LIM} Name:\t#{ name } Desc:\t#{ @description || N_A} Responsible:\t#{ @handler || N_A} Accepts:\t#{ @arguments || N_A} Returns: \tsuccess:\t#{ @returns && @returns.fetch(:success, N_A) || N_A } \tfailure:\t#{ @returns && @returns.fetch(:failure, N_A) || N_A } #{LIM} DOC end
handler(klass)
click to toggle source
# File lib/interface/port_entity.rb, line 48 def handler(klass) @handler = klass end
proxy(obj, options={})
click to toggle source
# File lib/interface/port_entity.rb, line 28 def proxy(obj, options={}) return nil unless @proxy_factory @proxy_factory.call(struct: @struct, contract: @contract, handler: @handler, proxy_model: @proxy_model).new(obj, options) end
proxy_factory(klass)
click to toggle source
# File lib/interface/port_entity.rb, line 20 def proxy_factory(klass) @proxy_factory = klass end
proxy_model(name)
click to toggle source
# File lib/interface/port_entity.rb, line 24 def proxy_model(name) @proxy_model = name end
returns(klass)
click to toggle source
# File lib/interface/port_entity.rb, line 56 def returns(klass) @adapter = klass end
struct(*fields)
click to toggle source
# File lib/interface/port_entity.rb, line 16 def struct(*fields) @struct = fields end
wrap_call()
click to toggle source
# File lib/interface/port_entity.rb, line 62 def wrap_call; end
Private Instance Methods
_callee()
click to toggle source
# File lib/interface/port_entity.rb, line 80 def _callee return @handler if @adapter.nil? @adapter.new(@handler) end