interface-dsl 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/interface/{adapter.rb → default_adapter.rb} +9 -7
- data/lib/interface/default_settings.rb +8 -0
- data/lib/interface/dsl/version.rb +1 -1
- data/lib/interface/dsl.rb +14 -9
- data/lib/interface/errors.rb +11 -0
- data/lib/interface/port_entity.rb +21 -13
- data/lib/interface.rb +7 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e8e9d4a6a3e4193121aa9810bb856eaa9b4b55f
|
4
|
+
data.tar.gz: b57a5f53fb5f71e1f429d1e2fb29ece754fb93aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c531aa1457a25afca68e02a7c79ca0abeec3d2d0e3a4fe29d2dcf2932e9934c0bec2197771afd42b4e5a2d23ddc51d48432fa7885bcfdd9a68d3efbefe3ce38f
|
7
|
+
data.tar.gz: 0e140c323d173e97f18fb2df08ef9b8ffcdc678d25986e665183ada64deb3f87a2205011b6690d2e6a60de951bd63fffc26db067d8571550a979f9ceab62ce9f
|
@@ -1,31 +1,33 @@
|
|
1
1
|
module Interface
|
2
|
-
class
|
2
|
+
class DefaultAdapter
|
3
3
|
CallingError = Class.new(StandardError)
|
4
4
|
InterfaceError = Class.new(StandardError)
|
5
5
|
|
6
6
|
extend FactoryMethods
|
7
7
|
|
8
|
-
|
8
|
+
deffactory :call
|
9
9
|
|
10
10
|
def initialize(callable)
|
11
11
|
@callable = callable
|
12
12
|
end
|
13
13
|
|
14
|
-
def call
|
14
|
+
def call(*args, &block)
|
15
15
|
unless callable.respond_to?(:call)
|
16
16
|
fail(InterfaceError("#{callable.class} is not callable!"))
|
17
17
|
end
|
18
18
|
|
19
|
-
_call
|
19
|
+
_call(*args, &block)
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
attr_reader :callable
|
25
|
+
|
26
|
+
def _call(*args, &block)
|
27
|
+
result = callable.call(*args, &block)
|
26
28
|
if result.is_a?(Array)
|
27
29
|
status, _result = result
|
28
|
-
status == :ok || fail(
|
30
|
+
status == :ok || fail(CallingError("Error while calling #{callable.class}: #{_result}"))
|
29
31
|
_result
|
30
32
|
else
|
31
33
|
result
|
data/lib/interface/dsl.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
require "interface"
|
2
|
-
require "interface/dsl/version"
|
3
2
|
|
4
3
|
module Interface
|
5
4
|
module DSL
|
6
|
-
|
7
|
-
|
5
|
+
def defsettings(configuration_class)
|
6
|
+
if !configuration_class.is_a?(Class) || !configuration_class.is_a?(Module)
|
7
|
+
fail(::Interface::Errors::UnexpectedInstanceError.new('Only classes and modules are supported'))
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
@settings ||= configuration_class
|
11
|
+
end
|
11
12
|
|
12
13
|
def interface(name, &block)
|
13
14
|
if interfaces.key?(name)
|
14
|
-
fail(
|
15
|
+
fail(::Interface::Errors::ImmutableInterfaceError.new("Interface can't be redefined or reopened! Use .extend_api method"))
|
15
16
|
end
|
16
17
|
|
17
18
|
interfaces.merge!(name => ::Interface::PortGroup.new(name, self).tap do |group|
|
@@ -60,12 +61,16 @@ module Interface
|
|
60
61
|
@points ||= Hashie::Mash.new
|
61
62
|
end
|
62
63
|
|
64
|
+
def _settings
|
65
|
+
@settings || ::Interface::DefaultSettings
|
66
|
+
end
|
67
|
+
|
63
68
|
private
|
64
69
|
|
65
70
|
def check_top_level_enpoint_policy
|
66
|
-
return if
|
71
|
+
return if _settings.config.allow_top_level_api_endpoints? || !top_level?
|
67
72
|
|
68
|
-
fail(
|
73
|
+
fail(::Interface::Errors::OrphanPortError.new("Can not be defined as a top level Interface"))
|
69
74
|
end
|
70
75
|
|
71
76
|
def top_level?
|
@@ -89,7 +94,7 @@ module Interface
|
|
89
94
|
end
|
90
95
|
|
91
96
|
def define_entity(name, &block)
|
92
|
-
::Interface::PortEntity.new(name).tap { |port| port.instance_eval(&block) }
|
97
|
+
::Interface::PortEntity.new(name, _settings.config.response_adapter).tap { |port| port.instance_eval(&block) }
|
93
98
|
end
|
94
99
|
end
|
95
100
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Interface
|
2
|
+
module Errors
|
3
|
+
BaseError = Class.new(StandardError)
|
4
|
+
|
5
|
+
OrphanPortError = Class.new(BaseError)
|
6
|
+
ImmutableInterfaceError = Class.new(BaseError)
|
7
|
+
InvalidInputError = Class.new(BaseError)
|
8
|
+
HandlerMissingError = Class.new(BaseError)
|
9
|
+
UnexpectedInstanceError = Class.new(BaseError)
|
10
|
+
end
|
11
|
+
end
|
@@ -1,10 +1,5 @@
|
|
1
1
|
module Interface
|
2
|
-
|
3
|
-
# => define Schemas with dry-validation
|
4
|
-
class PortEntity < Struct.new(:name)
|
5
|
-
WTFError = Class.new(StandardError)
|
6
|
-
InvalidInputError = Class.new(StandardError)
|
7
|
-
|
2
|
+
class PortEntity < Struct.new(:name, :default_adapter)
|
8
3
|
N_A = 'N/A'.freeze
|
9
4
|
LIM = ('-' * 48).freeze
|
10
5
|
|
@@ -14,17 +9,26 @@ module Interface
|
|
14
9
|
|
15
10
|
def call(*args, &block)
|
16
11
|
if @handler.nil?
|
17
|
-
fail(
|
12
|
+
fail(::Interface::Errors::HandlerMissingError.new("Handler is undefined"))
|
18
13
|
end
|
19
14
|
|
20
15
|
if !@contract.nil?
|
21
|
-
fail(InvalidInputError.new("Empty argument list doesn not comply with the Contract")) if args.empty?
|
16
|
+
fail(::Interface::Errors::InvalidInputError.new("Empty argument list doesn not comply with the Contract")) if args.empty?
|
22
17
|
|
23
18
|
errors = @contract.call(*args).errors
|
24
|
-
fail(InvalidInputError.new(errors)) if errors.any?
|
19
|
+
fail(::Interface::Errors::InvalidInputError.new(errors)) if errors.any?
|
25
20
|
end
|
26
21
|
|
27
|
-
|
22
|
+
# this is a decent source of bugs.
|
23
|
+
caller = if !@adapter.nil?
|
24
|
+
@adapter.new(@handler)
|
25
|
+
elsif !default_adapter.nil?
|
26
|
+
default_adapter.new(@handler)
|
27
|
+
else
|
28
|
+
@handler
|
29
|
+
end
|
30
|
+
|
31
|
+
caller.call(*args, &block)
|
28
32
|
end
|
29
33
|
|
30
34
|
def handler(klass)
|
@@ -35,11 +39,15 @@ module Interface
|
|
35
39
|
@contract = validation_schema
|
36
40
|
end
|
37
41
|
|
38
|
-
def returns(
|
39
|
-
|
40
|
-
failure: [:error, String] }
|
42
|
+
def returns(klass)
|
43
|
+
@adapter = klass
|
41
44
|
end
|
42
45
|
|
46
|
+
# def returns(hash)
|
47
|
+
# { success: [:ok, Object],
|
48
|
+
# failure: [:error, String] }
|
49
|
+
# end
|
50
|
+
|
43
51
|
#TODO
|
44
52
|
def before_call; end
|
45
53
|
def after_call; end
|
data/lib/interface.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
require 'dry-configurable'
|
2
2
|
require 'dry-validation'
|
3
3
|
require 'factorymethods'
|
4
|
+
require 'interface/dsl/version'
|
5
|
+
require 'hashie'
|
4
6
|
|
5
7
|
module Interface
|
6
|
-
|
8
|
+
autoload :PortGroup, 'interface/port_group'
|
9
|
+
autoload :PortEntity, 'interface/port_entity'
|
10
|
+
autoload :Errors, 'interface/errors'
|
7
11
|
|
8
|
-
|
12
|
+
autoload :DefaultSettings, 'interface/default_settings'
|
13
|
+
autoload :DefaultAdapter, 'interface/default_adapter'
|
9
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interface-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksiy Kurnenkov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|
@@ -140,9 +140,11 @@ files:
|
|
140
140
|
- bin/setup
|
141
141
|
- interface-dsl.gemspec
|
142
142
|
- lib/interface.rb
|
143
|
-
- lib/interface/
|
143
|
+
- lib/interface/default_adapter.rb
|
144
|
+
- lib/interface/default_settings.rb
|
144
145
|
- lib/interface/dsl.rb
|
145
146
|
- lib/interface/dsl/version.rb
|
147
|
+
- lib/interface/errors.rb
|
146
148
|
- lib/interface/port_entity.rb
|
147
149
|
- lib/interface/port_group.rb
|
148
150
|
homepage: https://github.com/o-kurnenkov/interface-dsl
|