Class: Interface::PortEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/interface/port_entity.rb

Constant Summary collapse

N_A =
'N/A'.freeze
LIM =
('-' * 48).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, adapter) ⇒ PortEntity

Returns a new instance of PortEntity.



8
9
10
# File 'lib/interface/port_entity.rb', line 8

def initialize(name, adapter)
  @name, @adapter = name, adapter
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/interface/port_entity.rb', line 6

def name
  @name
end

Instance Method Details

#after_callObject



50
# File 'lib/interface/port_entity.rb', line 50

def after_call; end

#before_callObject

TODO



49
# File 'lib/interface/port_entity.rb', line 49

def before_call; end

#call(*args, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/interface/port_entity.rb', line 16

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) ⇒ Object



35
36
37
# File 'lib/interface/port_entity.rb', line 35

def contract(validation_schema)
  @contract = validation_schema
end

#describe(text) ⇒ Object



12
13
14
# File 'lib/interface/port_entity.rb', line 12

def describe(text)
  @description = text
end

#docObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/interface/port_entity.rb', line 53

def doc
  puts "\#{LIM}\nName:\\t\#{ name }\nDesc:\\t\#{        @description    || N_A}\nResponsible:\\t\#{ @handler || N_A}\nAccepts:\\t\#{     @arguments      || N_A}\nReturns:\n\\tsuccess:\\t\#{   @returns && @returns.fetch(:success, N_A) || N_A }\n\\tfailure:\\t\#{   @returns && @returns.fetch(:failure, N_A) || N_A }\n\#{LIM}\n  DOC\nend\n"

#handler(klass) ⇒ Object



31
32
33
# File 'lib/interface/port_entity.rb', line 31

def handler(klass)
  @handler = klass
end

#returns(klass) ⇒ Object



39
40
41
# File 'lib/interface/port_entity.rb', line 39

def returns(klass)
  @adapter = klass
end

#wrap_callObject



51
# File 'lib/interface/port_entity.rb', line 51

def wrap_call; end