Class: Interface::PortEntity
- Inherits:
-
Object
- Object
- Interface::PortEntity
- Defined in:
- lib/interface/port_entity.rb
Constant Summary collapse
- N_A =
'N/A'.freeze
- LIM =
('-' * 48).freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #after_call ⇒ Object
-
#before_call ⇒ Object
TODO.
- #call(*args, &block) ⇒ Object
- #contract(validation_schema) ⇒ Object
- #describe(text) ⇒ Object
- #doc ⇒ Object
- #handler(klass) ⇒ Object
-
#initialize(name, adapter) ⇒ PortEntity
constructor
A new instance of PortEntity.
- #returns(klass) ⇒ Object
- #wrap_call ⇒ Object
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
#name ⇒ Object (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_call ⇒ Object
50 |
# File 'lib/interface/port_entity.rb', line 50 def after_call; end |
#before_call ⇒ Object
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 |
#doc ⇒ Object
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_call ⇒ Object
51 |
# File 'lib/interface/port_entity.rb', line 51 def wrap_call; end |