corindon 0.4.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/corindon.gemspec +1 -0
- data/lib/corindon/dependency_injection/container.rb +83 -29
- data/lib/corindon/dependency_injection/definition.rb +13 -32
- data/lib/corindon/dependency_injection/dsl.rb +26 -13
- data/lib/corindon/dependency_injection/injectable.rb +22 -8
- data/lib/corindon/dependency_injection/injector.rb +2 -0
- data/lib/corindon/dependency_injection/ruby_compat.rb +27 -0
- data/lib/corindon/dependency_injection/testing/mock_utils.rb +40 -0
- data/lib/corindon/dependency_injection/token/service_call_token.rb +1 -21
- data/lib/corindon/dependency_injection/token/service_factory_token.rb +24 -0
- data/lib/corindon/{ext/guards.rb → guards/ext.rb} +4 -4
- data/lib/corindon/result/errors/bad_return_type_error.rb +19 -0
- data/lib/corindon/{ext/guards/error.rb → result/errors/result_error.rb} +3 -3
- data/lib/corindon/result/ext.rb +25 -0
- data/lib/corindon/result/failure.rb +27 -0
- data/lib/corindon/result/result.rb +32 -0
- data/lib/corindon/result/success.rb +39 -0
- data/lib/corindon/{ext/something.rb → something/ext.rb} +2 -2
- data/lib/corindon/version.rb +1 -1
- metadata +27 -11
- data/lib/corindon/console/application.rb +0 -15
- data/lib/corindon/console/base_command.rb +0 -13
- data/lib/corindon/console/input.rb +0 -8
- data/lib/corindon/console/output.rb +0 -8
- data/lib/corindon/dependency_injection/id/id_generator.rb +0 -12
- data/lib/corindon/dependency_injection/id/uuid_generator.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9899f5321cf96c41569182938051a815f5baed7d04bda1f88a649c21b50df0b3
|
4
|
+
data.tar.gz: c6a9495fc8c46760fb5a09780bc8bbc12ae95deb4e0d7331042f7640f0d380d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66590e780392422933ccceb3596bb9e97d4ef6eb9e4d5685847cfe128b5f5d0a196723aa626f5bab711b011dad84a5987fc2b1946dd850b0e255226308bdd18a
|
7
|
+
data.tar.gz: bd262475a0fa7d10b565ef357d066db7b94c310eff89188438683ff26322de2fb5bcf87398b676ded30ef0fac18c81d251cb0c0f217ed20208bd02ba96a0629e
|
data/corindon.gemspec
CHANGED
@@ -3,42 +3,68 @@
|
|
3
3
|
module Corindon
|
4
4
|
module DependencyInjection
|
5
5
|
class Container
|
6
|
-
using Ext
|
6
|
+
using Something::Ext
|
7
7
|
|
8
|
-
attr_reader :id_generator
|
9
8
|
attr_reader :injector
|
10
9
|
|
11
|
-
# @param [
|
12
|
-
def initialize(
|
13
|
-
@id_generator = id_generator
|
10
|
+
# @param [Array<Definition>] definitions
|
11
|
+
def initialize(definitions: [], parameters: {}, service_built_listeners: [])
|
14
12
|
@services = {}
|
15
13
|
@definitions = {}
|
16
|
-
@parameters =
|
14
|
+
@parameters = parameters
|
17
15
|
@tags = Hash.new { |hash, key| hash[key] = [] }
|
18
16
|
|
19
17
|
@injector = Injector.new(container: self)
|
18
|
+
|
19
|
+
definitions.each { |d| register_definition(d) }
|
20
|
+
|
21
|
+
@service_built_listeners = service_built_listeners
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Container]
|
25
|
+
def dup
|
26
|
+
Container.new(
|
27
|
+
definitions: definitions.values,
|
28
|
+
parameters: parameters.dup,
|
29
|
+
service_built_listeners: service_built_listeners
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [Definition, Injectable, Class]
|
34
|
+
# @return [Definition]
|
35
|
+
def as_definition(def_or_injectable)
|
36
|
+
if def_or_injectable.is_a?(Definition)
|
37
|
+
def_or_injectable
|
38
|
+
elsif def_or_injectable.is_a?(Injectable)
|
39
|
+
def_or_injectable.definition
|
40
|
+
elsif def_or_injectable.is_a?(Class)
|
41
|
+
Definition.new(def_or_injectable)
|
42
|
+
else
|
43
|
+
raise StandardError.new("Don't know how to build #{def_or_injectable}")
|
44
|
+
end
|
20
45
|
end
|
21
46
|
|
22
|
-
# @param [Class]
|
47
|
+
# @param [Class, Injectable, Definition] def_or_injectable
|
23
48
|
# @return [String]
|
24
|
-
def add_definition(
|
25
|
-
definition =
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
else
|
30
|
-
Definition.new(klass)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Generate an id if set to anonymous when registering
|
34
|
-
# If a definition is set to be anonymous but an id is provided zhen registering, use this id instead<
|
35
|
-
if anonymous || (definition.anonymous? && id.nil?)
|
36
|
-
id = id_generator.generate
|
49
|
+
def add_definition(def_or_injectable, context: {}, &block)
|
50
|
+
definition = as_definition(def_or_injectable)
|
51
|
+
|
52
|
+
if block.sth?
|
53
|
+
definition = Dsl.from_definition(definition).exec(context: context, &block)
|
37
54
|
end
|
38
55
|
|
39
|
-
id =
|
40
|
-
|
41
|
-
|
56
|
+
id = definition.id || to_id(def_or_injectable)
|
57
|
+
|
58
|
+
register_definition(
|
59
|
+
Definition.new(
|
60
|
+
definition.object_source,
|
61
|
+
id: id,
|
62
|
+
args: definition.args,
|
63
|
+
kwargs: definition.kwargs,
|
64
|
+
calls: definition.calls,
|
65
|
+
tags: definition.tags
|
66
|
+
)
|
67
|
+
)
|
42
68
|
|
43
69
|
id
|
44
70
|
end
|
@@ -60,6 +86,11 @@ module Corindon
|
|
60
86
|
definitions.key?(to_id(key))
|
61
87
|
end
|
62
88
|
|
89
|
+
# Clears all the cache of services
|
90
|
+
def clear
|
91
|
+
@services = {}
|
92
|
+
end
|
93
|
+
|
63
94
|
# @param [Class, #to_s] key
|
64
95
|
# @return [Object]
|
65
96
|
def get(key)
|
@@ -92,26 +123,49 @@ module Corindon
|
|
92
123
|
parameters.fetch(to_id(key))
|
93
124
|
end
|
94
125
|
|
126
|
+
# @param [Proc{Object, Container}] listener
|
127
|
+
def on_service_built(listener)
|
128
|
+
service_built_listeners << listener
|
129
|
+
end
|
130
|
+
|
95
131
|
private
|
96
132
|
|
133
|
+
# @return [Hash{String=>Definition}]
|
97
134
|
attr_reader :definitions
|
98
135
|
attr_reader :parameters
|
99
136
|
attr_reader :services
|
100
137
|
attr_reader :tags
|
138
|
+
attr_reader :service_built_listeners
|
139
|
+
|
140
|
+
def register_definition(definition)
|
141
|
+
definitions[definition.id] = definition
|
142
|
+
definition.tags.each { |tag| tags[tag] << definition.id }
|
143
|
+
end
|
101
144
|
|
102
145
|
def build_service(id)
|
103
|
-
definitions.fetch(id)
|
104
|
-
services[id] =
|
146
|
+
service = injector.resolve(definitions.fetch(id)).tap do |svc|
|
147
|
+
services[id] = svc
|
105
148
|
end
|
149
|
+
|
150
|
+
service_built_listeners.each do |listener|
|
151
|
+
listener.call(service, self)
|
152
|
+
end
|
153
|
+
|
154
|
+
service
|
106
155
|
end
|
107
156
|
|
108
|
-
def injectable?(
|
109
|
-
|
157
|
+
def injectable?(object)
|
158
|
+
object.is_a?(Injectable)
|
110
159
|
end
|
111
160
|
|
112
|
-
# @param [Class, #to_s] key
|
161
|
+
# @param [Injectable, Identifiable, Class, Definition, #to_s] key
|
162
|
+
# @return [String]
|
113
163
|
def to_id(key)
|
114
|
-
if key.is_a?(
|
164
|
+
if key.is_a?(Definition)
|
165
|
+
key.id
|
166
|
+
elsif injectable?(key)
|
167
|
+
to_id(key.definition)
|
168
|
+
elsif key.is_a?(Class)
|
115
169
|
key.name
|
116
170
|
else
|
117
171
|
key.to_s
|
@@ -5,59 +5,40 @@ require 'semantic'
|
|
5
5
|
module Corindon
|
6
6
|
module DependencyInjection
|
7
7
|
class Definition
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :object_source
|
9
9
|
attr_reader :args
|
10
10
|
attr_reader :kwargs
|
11
11
|
attr_reader :calls
|
12
12
|
attr_reader :tags
|
13
|
+
# @return [String]
|
13
14
|
attr_reader :id
|
14
15
|
|
15
|
-
def initialize(
|
16
|
-
@
|
16
|
+
def initialize(object_source, args: [], kwargs: {}, calls: [], tags: [], id: nil)
|
17
|
+
@object_source = object_source
|
17
18
|
@args = args
|
18
19
|
@kwargs = kwargs
|
19
20
|
@calls = calls
|
20
21
|
@tags = tags
|
21
22
|
@id = id
|
22
|
-
@anonymous = anonymous
|
23
23
|
end
|
24
24
|
|
25
25
|
# @param [Injector] injector
|
26
|
-
#
|
26
|
+
# @return [Object]
|
27
27
|
def build(injector)
|
28
|
-
|
28
|
+
source = if object_source.is_a?(Class)
|
29
|
+
[object_source, :new]
|
30
|
+
else
|
31
|
+
injector.resolve(object_source)
|
32
|
+
end
|
33
|
+
|
34
|
+
object = RubyCompat.do_call(*source, injector.resolve(args), injector.resolve(kwargs))
|
29
35
|
|
30
36
|
calls.each do |(call, call_args, call_kwargs)|
|
31
|
-
do_call(object, call, injector.resolve(call_args), injector.resolve(call_kwargs))
|
37
|
+
RubyCompat.do_call(object, call, injector.resolve(call_args), injector.resolve(call_kwargs))
|
32
38
|
end
|
33
39
|
|
34
40
|
object
|
35
41
|
end
|
36
|
-
|
37
|
-
# @return [Boolean]
|
38
|
-
def anonymous?
|
39
|
-
@anonymous
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
if ::Semantic::Version.new(RUBY_VERSION).satisfies?(">= 2.7.0")
|
45
|
-
def do_call(obj, method, args, kwargs)
|
46
|
-
obj.send(method, *args, **kwargs)
|
47
|
-
end
|
48
|
-
else
|
49
|
-
def do_call(obj, method, args, kwargs)
|
50
|
-
if args.empty? && kwargs.empty?
|
51
|
-
obj.send(method)
|
52
|
-
elsif args.empty?
|
53
|
-
obj.send(method, **kwargs)
|
54
|
-
elsif kwargs.empty?
|
55
|
-
obj.send(method, *args)
|
56
|
-
else
|
57
|
-
obj.send(method, *args, **kwargs)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
42
|
end
|
62
43
|
end
|
63
44
|
end
|
@@ -3,22 +3,41 @@
|
|
3
3
|
module Corindon
|
4
4
|
module DependencyInjection
|
5
5
|
class Dsl
|
6
|
+
class << self
|
7
|
+
# @param [Definition] definition
|
8
|
+
# @return [Dsl]
|
9
|
+
def from_definition(definition)
|
10
|
+
new(
|
11
|
+
definition.object_source,
|
12
|
+
id: definition.id,
|
13
|
+
args: definition.args,
|
14
|
+
kwargs: definition.kwargs,
|
15
|
+
calls: definition.calls,
|
16
|
+
tags: definition.tags
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
6
21
|
# @param [Class] klass
|
7
|
-
def initialize(klass, args: [], kwargs: {}, id: nil,
|
22
|
+
def initialize(klass, args: [], kwargs: {}, id: nil, calls: [], tags: [])
|
8
23
|
@klass = klass
|
9
24
|
@args = args
|
10
25
|
@kwargs = kwargs
|
11
|
-
@calls =
|
12
|
-
@tags =
|
26
|
+
@calls = calls
|
27
|
+
@tags = tags
|
13
28
|
@id = id
|
14
|
-
@anonymous = anonymous
|
15
29
|
end
|
16
30
|
|
31
|
+
# @param [Hash] context
|
17
32
|
# @return [Definition]
|
18
|
-
def exec(&block)
|
19
|
-
|
33
|
+
def exec(context: {}, &block)
|
34
|
+
if context.is_a?(Hash)
|
35
|
+
context = OpenStruct.new(context)
|
36
|
+
end
|
37
|
+
|
38
|
+
instance_exec(context, &block)
|
20
39
|
|
21
|
-
Definition.new(@klass, args: @args, kwargs: @kwargs, calls: @calls, tags: @tags, id: @id
|
40
|
+
Definition.new(@klass, args: @args, kwargs: @kwargs, calls: @calls, tags: @tags, id: @id)
|
22
41
|
end
|
23
42
|
|
24
43
|
def args(*arguments, **kv_arguments)
|
@@ -33,15 +52,9 @@ module Corindon
|
|
33
52
|
|
34
53
|
# @param [String] id
|
35
54
|
def id(id)
|
36
|
-
@anonymous = false
|
37
55
|
@id = id
|
38
56
|
end
|
39
57
|
|
40
|
-
def anonymous!
|
41
|
-
@anonymous = true
|
42
|
-
@id = nil
|
43
|
-
end
|
44
|
-
|
45
58
|
# @param [Class, #to_s] key
|
46
59
|
# @return [Token::ParameterToken]
|
47
60
|
def param(key)
|
@@ -3,22 +3,36 @@
|
|
3
3
|
module Corindon
|
4
4
|
module DependencyInjection
|
5
5
|
module Injectable
|
6
|
-
def definition
|
7
|
-
Definition.new(self)
|
8
|
-
end
|
9
|
-
|
10
6
|
refine Class do
|
7
|
+
def factory(service, method)
|
8
|
+
Token::ServiceFactoryToken.new(service, method)
|
9
|
+
end
|
10
|
+
|
11
|
+
def make_parameter(name)
|
12
|
+
Token::ParameterToken.new(key: "#{self.name.downcase.gsub(/::/, '.')}.#{name}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def make_definition(name, source, *args, **kwargs, &block)
|
16
|
+
do_make_definition("#{self.name.downcase.gsub(/::/, '.')}.#{name}", source, args: args, kwargs: kwargs, &block)
|
17
|
+
end
|
18
|
+
|
11
19
|
def injectable(*args, **kwargs, &block)
|
12
|
-
|
20
|
+
extend Injectable
|
13
21
|
|
14
22
|
define_singleton_method :definition do
|
23
|
+
do_make_definition(name, self, args: args, kwargs: kwargs, &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def do_make_definition(name, source, args:, kwargs:, &block)
|
15
30
|
if block.nil?
|
16
|
-
Definition.new(
|
31
|
+
Definition.new(source, args: args, kwargs: kwargs, id: name)
|
17
32
|
else
|
18
|
-
Dsl.new(
|
33
|
+
Dsl.new(source, args: args, kwargs: kwargs, id: name).exec(&block)
|
19
34
|
end
|
20
35
|
end
|
21
|
-
end
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
class RubyCompat
|
6
|
+
class << self
|
7
|
+
if ::Semantic::Version.new(RUBY_VERSION).satisfies?('>= 2.7.0')
|
8
|
+
def do_call(obj, method, args, kwargs)
|
9
|
+
obj.send(method, *args, **kwargs)
|
10
|
+
end
|
11
|
+
else
|
12
|
+
def do_call(obj, method, args, kwargs)
|
13
|
+
if args.empty? && kwargs.empty?
|
14
|
+
obj.send(method)
|
15
|
+
elsif args.empty?
|
16
|
+
obj.send(method, **kwargs)
|
17
|
+
elsif kwargs.empty?
|
18
|
+
obj.send(method, *args)
|
19
|
+
else
|
20
|
+
obj.send(method, *args, **kwargs)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Testing
|
6
|
+
# Defines the `mock_definition` on Container allowing to mock services returned by the container for a given Definition
|
7
|
+
module MockUtils
|
8
|
+
refine Container do
|
9
|
+
# Allow to provide a specific value that the definition will resolve to
|
10
|
+
# @param [Definition] definition
|
11
|
+
# @param [Object] value
|
12
|
+
def mock_definition(definition, value)
|
13
|
+
singleton_class.prepend MockUtils unless is_a?(MockUtils)
|
14
|
+
|
15
|
+
add_definition(definition) if !has?(definition)
|
16
|
+
|
17
|
+
id = to_id(definition)
|
18
|
+
mocks[definition] = services[id] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
using self
|
23
|
+
|
24
|
+
def mocks
|
25
|
+
@mocks ||= {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def dup
|
29
|
+
new_instance = super
|
30
|
+
|
31
|
+
mocks.each do |definition, value|
|
32
|
+
new_instance.mock_definition(definition, value)
|
33
|
+
end
|
34
|
+
|
35
|
+
new_instance
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -27,33 +27,13 @@ module Corindon
|
|
27
27
|
|
28
28
|
# @param [Injector] injector
|
29
29
|
def resolve(injector:)
|
30
|
-
do_call(
|
30
|
+
RubyCompat.do_call(
|
31
31
|
injector.resolve(service),
|
32
32
|
method,
|
33
33
|
injector.resolve(args),
|
34
34
|
injector.resolve(kwargs)
|
35
35
|
)
|
36
36
|
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
if ::Semantic::Version.new(RUBY_VERSION).satisfies?(">= 2.7.0")
|
41
|
-
def do_call(obj, method, args, kwargs)
|
42
|
-
obj.send(method, *args, **kwargs)
|
43
|
-
end
|
44
|
-
else
|
45
|
-
def do_call(obj, method, args, kwargs)
|
46
|
-
if args.empty? && kwargs.empty?
|
47
|
-
obj.send(method)
|
48
|
-
elsif args.empty?
|
49
|
-
obj.send(method, **kwargs)
|
50
|
-
elsif kwargs.empty?
|
51
|
-
obj.send(method, *args)
|
52
|
-
else
|
53
|
-
obj.send(method, *args, **kwargs)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
37
|
end
|
58
38
|
end
|
59
39
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Token
|
6
|
+
class ServiceFactoryToken < InjectionToken
|
7
|
+
attr_reader :service
|
8
|
+
attr_reader :method
|
9
|
+
|
10
|
+
def initialize(service, method)
|
11
|
+
super()
|
12
|
+
|
13
|
+
@service = service
|
14
|
+
@method = method
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [Injector] injector
|
18
|
+
def resolve(injector:)
|
19
|
+
[injector.resolve(service), method]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Corindon
|
4
|
-
module
|
5
|
-
module
|
4
|
+
module Guards
|
5
|
+
module Ext
|
6
6
|
refine Object do
|
7
7
|
def unimplemented!(message = nil)
|
8
|
-
raise
|
8
|
+
raise NotImplementedError.new(message || 'This method is not implemented.')
|
9
9
|
end
|
10
10
|
|
11
11
|
def unreachable!(message = nil)
|
12
|
-
raise
|
12
|
+
raise StandardError.new(message || 'Reached unreachable code.')
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
module Errors
|
6
|
+
class BadReturnTypeError < ResultError
|
7
|
+
# @return [Object]
|
8
|
+
attr_reader :value
|
9
|
+
|
10
|
+
# @param [Object] value
|
11
|
+
def initialize(value)
|
12
|
+
super("Expected a Result, got #{value}")
|
13
|
+
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
module Ext
|
6
|
+
refine Object do
|
7
|
+
def rescue_failure(&block)
|
8
|
+
block.call
|
9
|
+
rescue StandardError => error
|
10
|
+
Corindon::Result::Failure.new(error)
|
11
|
+
end
|
12
|
+
|
13
|
+
# rubocop:disable Naming/MethodName
|
14
|
+
def Failure(error)
|
15
|
+
Corindon::Result::Failure.new(error)
|
16
|
+
end
|
17
|
+
|
18
|
+
def Success(value)
|
19
|
+
Corindon::Result::Success.new(value)
|
20
|
+
end
|
21
|
+
# rubocop:enable Naming/MethodName
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
class Failure < Result
|
6
|
+
# @return [Exception]
|
7
|
+
attr_reader :error
|
8
|
+
|
9
|
+
# @param [Exception] error
|
10
|
+
def initialize(error)
|
11
|
+
super()
|
12
|
+
|
13
|
+
@error = error
|
14
|
+
end
|
15
|
+
|
16
|
+
# @raise [Exception]
|
17
|
+
def unwrap!
|
18
|
+
raise error
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Boolean]
|
22
|
+
def failure?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
using Corindon::Guards::Ext
|
4
|
+
|
5
|
+
module Corindon
|
6
|
+
module Result
|
7
|
+
class Result
|
8
|
+
# @return [Boolean]
|
9
|
+
def success?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Boolean]
|
14
|
+
def failure?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
# @raise [Exception] if called on a Failure
|
19
|
+
# @return [Object]
|
20
|
+
def unwrap!
|
21
|
+
unimplemented!
|
22
|
+
end
|
23
|
+
|
24
|
+
# @yieldparam [Object] value
|
25
|
+
# @yieldreturn [Result]
|
26
|
+
# @return [Result]
|
27
|
+
def and_then(&_block)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
class Success < Result
|
6
|
+
# @return [Object]
|
7
|
+
attr_reader :value
|
8
|
+
|
9
|
+
# @param [Object] value
|
10
|
+
def initialize(value)
|
11
|
+
super()
|
12
|
+
|
13
|
+
@value = value
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Boolean]
|
17
|
+
def success?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Object]
|
22
|
+
def unwrap!
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
def and_then(&block)
|
27
|
+
retval = block.call(value)
|
28
|
+
|
29
|
+
if retval.is_a?(Result)
|
30
|
+
retval
|
31
|
+
else
|
32
|
+
Failure.new(Errors::BadReturnTypeError.new(retval))
|
33
|
+
end
|
34
|
+
rescue StandardError => error
|
35
|
+
Failure.new(error)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/corindon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corindon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Piotaix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semantic
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.1
|
83
97
|
description:
|
84
98
|
email: remi@piotaix.fr
|
85
99
|
executables: []
|
@@ -88,25 +102,27 @@ extra_rdoc_files: []
|
|
88
102
|
files:
|
89
103
|
- corindon.gemspec
|
90
104
|
- lib/corindon.rb
|
91
|
-
- lib/corindon/console/application.rb
|
92
|
-
- lib/corindon/console/base_command.rb
|
93
|
-
- lib/corindon/console/input.rb
|
94
|
-
- lib/corindon/console/output.rb
|
95
105
|
- lib/corindon/dependency_injection/container.rb
|
96
106
|
- lib/corindon/dependency_injection/definition.rb
|
97
107
|
- lib/corindon/dependency_injection/dsl.rb
|
98
|
-
- lib/corindon/dependency_injection/id/id_generator.rb
|
99
|
-
- lib/corindon/dependency_injection/id/uuid_generator.rb
|
100
108
|
- lib/corindon/dependency_injection/injectable.rb
|
101
109
|
- lib/corindon/dependency_injection/injector.rb
|
110
|
+
- lib/corindon/dependency_injection/ruby_compat.rb
|
111
|
+
- lib/corindon/dependency_injection/testing/mock_utils.rb
|
102
112
|
- lib/corindon/dependency_injection/token/injection_token.rb
|
103
113
|
- lib/corindon/dependency_injection/token/parameter_token.rb
|
104
114
|
- lib/corindon/dependency_injection/token/service_call_token.rb
|
115
|
+
- lib/corindon/dependency_injection/token/service_factory_token.rb
|
105
116
|
- lib/corindon/dependency_injection/token/tagged_token.rb
|
106
117
|
- lib/corindon/dependency_injection/token/value_token.rb
|
107
|
-
- lib/corindon/ext
|
108
|
-
- lib/corindon/
|
109
|
-
- lib/corindon/
|
118
|
+
- lib/corindon/guards/ext.rb
|
119
|
+
- lib/corindon/result/errors/bad_return_type_error.rb
|
120
|
+
- lib/corindon/result/errors/result_error.rb
|
121
|
+
- lib/corindon/result/ext.rb
|
122
|
+
- lib/corindon/result/failure.rb
|
123
|
+
- lib/corindon/result/result.rb
|
124
|
+
- lib/corindon/result/success.rb
|
125
|
+
- lib/corindon/something/ext.rb
|
110
126
|
- lib/corindon/version.rb
|
111
127
|
homepage: https://gitlab.com/piotaixr/corindon
|
112
128
|
licenses:
|