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



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

def after_call; end

#before_callObject



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

def before_call; end

#call(*args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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 [email protected]?
  #   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



52
53
54
# File 'lib/interface/port_entity.rb', line 52

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



64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object



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

def handler(klass)
  @handler = klass
end

#proxy(obj, options = {}) ⇒ Object



28
29
30
31
# 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) ⇒ Object



20
21
22
# File 'lib/interface/port_entity.rb', line 20

def proxy_factory(klass)
  @proxy_factory = klass
end

#proxy_model(name) ⇒ Object



24
25
26
# File 'lib/interface/port_entity.rb', line 24

def proxy_model(name)
  @proxy_model = name
end

#returns(klass) ⇒ Object



56
57
58
# File 'lib/interface/port_entity.rb', line 56

def returns(klass)
  @adapter = klass
end

#struct(*fields) ⇒ Object



16
17
18
# File 'lib/interface/port_entity.rb', line 16

def struct(*fields)
  @struct = fields
end

#wrap_callObject



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

def wrap_call; end