Class: Interface::PortEntity
- Inherits:
-
Struct
- Object
- Struct
- Interface::PortEntity
- Defined in:
- lib/interface/port_entity.rb
Overview
TODO
> define Schemas with dry-validation
Constant Summary collapse
- WTFError =
Class.new(StandardError)
- InvalidInputError =
Class.new(StandardError)
- N_A =
'N/A'.freeze
- LIM =
('-' * 48).freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
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
- #returns(hash) ⇒ Object
- #wrap_call ⇒ Object
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/interface/port_entity.rb', line 4 def name @name end |
Instance Method Details
#after_call ⇒ Object
45 |
# File 'lib/interface/port_entity.rb', line 45 def after_call; end |
#before_call ⇒ Object
TODO
44 |
# File 'lib/interface/port_entity.rb', line 44 def before_call; end |
#call(*args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/interface/port_entity.rb', line 15 def call(*args, &block) if @handler.nil? fail(WTFError.new("WAT A HECK U DOIN'! THERE'S NO HANDLER TO CALL!")) end if !@contract.nil? fail(InvalidInputError.new("Empty argument list doesn not comply with the Contract")) if args.empty? errors = @contract.call(*args).errors fail(InvalidInputError.new(errors)) if errors.any? end @handler.call(*args, &block) end |
#contract(validation_schema) ⇒ Object
34 35 36 |
# File 'lib/interface/port_entity.rb', line 34 def contract(validation_schema) @contract = validation_schema end |
#describe(text) ⇒ Object
11 12 13 |
# File 'lib/interface/port_entity.rb', line 11 def describe(text) @description = text end |
#doc ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/interface/port_entity.rb', line 48 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
30 31 32 |
# File 'lib/interface/port_entity.rb', line 30 def handler(klass) @handler = klass end |
#returns(hash) ⇒ Object
38 39 40 41 |
# File 'lib/interface/port_entity.rb', line 38 def returns(hash) { success: [:ok, Object], failure: [:error, String] } end |
#wrap_call ⇒ Object
46 |
# File 'lib/interface/port_entity.rb', line 46 def wrap_call; end |