corindon 0.1.0 → 0.6.0
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 +2 -0
- data/lib/corindon/console/application.rb +15 -0
- data/lib/corindon/console/base_command.rb +13 -0
- data/lib/corindon/console/input.rb +8 -0
- data/lib/corindon/console/output.rb +8 -0
- data/lib/corindon/dependency_injection/container.rb +127 -0
- data/lib/corindon/dependency_injection/definition.rb +63 -0
- data/lib/corindon/dependency_injection/dsl.rb +78 -0
- data/lib/corindon/dependency_injection/id/id_generator.rb +12 -0
- data/lib/corindon/dependency_injection/id/uuid_generator.rb +14 -0
- data/lib/corindon/dependency_injection/injectable.rb +25 -0
- data/lib/corindon/dependency_injection/injector.rb +28 -0
- data/lib/corindon/dependency_injection/token/injection_token.rb +12 -0
- data/lib/corindon/dependency_injection/token/parameter_token.rb +22 -0
- data/lib/corindon/dependency_injection/token/service_call_token.rb +60 -0
- data/lib/corindon/dependency_injection/token/tagged_token.rb +24 -0
- data/lib/corindon/dependency_injection/token/value_token.rb +22 -0
- data/lib/corindon/ext/guards.rb +17 -0
- data/lib/corindon/ext/guards/error.rb +10 -0
- data/lib/corindon/result/errors/bad_return_type_error.rb +19 -0
- data/lib/corindon/result/errors/result_error.rb +10 -0
- data/lib/corindon/result/ext.rb +25 -0
- data/lib/corindon/result/failure.rb +22 -0
- data/lib/corindon/result/result.rb +24 -0
- data/lib/corindon/result/success.rb +34 -0
- data/lib/corindon/{ext/something.rb → something/ext.rb} +2 -2
- data/lib/corindon/version.rb +1 -1
- metadata +55 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae37025ed53b2bec8d329d9d640d40425406a0c6b2ba8fcf85ec573e5b0cdd6d
|
4
|
+
data.tar.gz: 3d6c2d3acac3f22c5c15b5128a3a7e005a4f1c6ea1508472d29bdcfb5eefc19c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d44b60b7a78a391211c194a62b1cabf76664dc2a2f2ab268bc716873468c7e9245f2c6acd18c344596d16b48e3b16ce8f1de028e3a8f30de6adc042f7e8dc9
|
7
|
+
data.tar.gz: 704342b6b6afe491f9c21f9de07841356edc8c02e504ac66646d195fc88b34733f65dfa3a25a0b0f6ab40927429a11e2dec640c2cbf6a5861fc0a2926dca0b37
|
data/corindon.gemspec
CHANGED
@@ -15,8 +15,10 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.required_ruby_version = '>= 2.6.0'
|
17
17
|
|
18
|
+
s.add_dependency 'semantic', '~> 1.6'
|
18
19
|
s.add_dependency 'zeitwerk', '~> 2.3'
|
19
20
|
|
21
|
+
s.add_development_dependency 'bundler'
|
20
22
|
s.add_development_dependency 'minitest', '~> 5.14'
|
21
23
|
s.add_development_dependency 'rake', '~> 13.0'
|
22
24
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
class Container
|
6
|
+
using Something::Ext
|
7
|
+
|
8
|
+
attr_reader :id_generator
|
9
|
+
attr_reader :injector
|
10
|
+
|
11
|
+
# @param [Id::IdGenerator] id_generator
|
12
|
+
def initialize(id_generator: Id::UuidGenerator.new)
|
13
|
+
@id_generator = id_generator
|
14
|
+
@services = {}
|
15
|
+
@definitions = {}
|
16
|
+
@parameters = {}
|
17
|
+
@tags = Hash.new { |hash, key| hash[key] = [] }
|
18
|
+
|
19
|
+
@injector = Injector.new(container: self)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [Class] klass
|
23
|
+
# @return [String]
|
24
|
+
def add_definition(klass, id: nil, anonymous: false, context: {}, &block)
|
25
|
+
definition = if injectable?(klass)
|
26
|
+
klass.definition
|
27
|
+
elsif block.sth?
|
28
|
+
Dsl.new(klass).exec(context: context, &block)
|
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
|
37
|
+
end
|
38
|
+
|
39
|
+
id = id || definition.id || to_id(klass)
|
40
|
+
definitions[id] = definition
|
41
|
+
definition.tags.each { |tag| tags[tag] << id }
|
42
|
+
|
43
|
+
id
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param [String] tag
|
47
|
+
# @return [Array<String>]
|
48
|
+
def tagged(tag)
|
49
|
+
if tags.key?(tag)
|
50
|
+
|
51
|
+
tags.fetch(tag)
|
52
|
+
else
|
53
|
+
[]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [Class, #to_s] key
|
58
|
+
# @return [Boolean]
|
59
|
+
def has?(key)
|
60
|
+
definitions.key?(to_id(key))
|
61
|
+
end
|
62
|
+
|
63
|
+
# Clears all the cache of services
|
64
|
+
def clear
|
65
|
+
@services = {}
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [Class, #to_s] key
|
69
|
+
# @return [Object]
|
70
|
+
def get(key)
|
71
|
+
id = to_id(key)
|
72
|
+
|
73
|
+
if has?(key)
|
74
|
+
services.fetch(id) { build_service(id) }
|
75
|
+
elsif injectable?(key)
|
76
|
+
key.definition.build(injector)
|
77
|
+
else
|
78
|
+
raise StandardError.new("No service #{id}")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# @param [Class, #to_s] key
|
83
|
+
# @param [Object] value
|
84
|
+
def set_parameter(name, value)
|
85
|
+
parameters[to_id(name)] = value
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param [Class, #to_s] key
|
89
|
+
# @return [Boolean]
|
90
|
+
def parameter?(key)
|
91
|
+
parameters.key?(to_id(key))
|
92
|
+
end
|
93
|
+
|
94
|
+
# @param [Class, #to_s] key
|
95
|
+
# @return [Object]
|
96
|
+
def parameter(key)
|
97
|
+
parameters.fetch(to_id(key))
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
attr_reader :definitions
|
103
|
+
attr_reader :parameters
|
104
|
+
attr_reader :services
|
105
|
+
attr_reader :tags
|
106
|
+
|
107
|
+
def build_service(id)
|
108
|
+
definitions.fetch(id).build(injector).tap do |service|
|
109
|
+
services[id] = service
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def injectable?(klass)
|
114
|
+
klass.is_a?(Class) && klass.ancestors.include?(Injectable)
|
115
|
+
end
|
116
|
+
|
117
|
+
# @param [Class, #to_s] key
|
118
|
+
def to_id(key)
|
119
|
+
if key.is_a?(Class)
|
120
|
+
key.name
|
121
|
+
else
|
122
|
+
key.to_s
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'semantic'
|
4
|
+
|
5
|
+
module Corindon
|
6
|
+
module DependencyInjection
|
7
|
+
class Definition
|
8
|
+
attr_reader :klass
|
9
|
+
attr_reader :args
|
10
|
+
attr_reader :kwargs
|
11
|
+
attr_reader :calls
|
12
|
+
attr_reader :tags
|
13
|
+
attr_reader :id
|
14
|
+
|
15
|
+
def initialize(klass, args: [], kwargs: {}, calls: [], tags: [], id: nil, anonymous: false)
|
16
|
+
@klass = klass
|
17
|
+
@args = args
|
18
|
+
@kwargs = kwargs
|
19
|
+
@calls = calls
|
20
|
+
@tags = tags
|
21
|
+
@id = id
|
22
|
+
@anonymous = anonymous
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Injector] injector
|
26
|
+
# # @return [Object]
|
27
|
+
def build(injector)
|
28
|
+
object = do_call(klass, :new, injector.resolve(args), injector.resolve(kwargs))
|
29
|
+
|
30
|
+
calls.each do |(call, call_args, call_kwargs)|
|
31
|
+
do_call(object, call, injector.resolve(call_args), injector.resolve(call_kwargs))
|
32
|
+
end
|
33
|
+
|
34
|
+
object
|
35
|
+
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
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
class Dsl
|
6
|
+
# @param [Class] klass
|
7
|
+
def initialize(klass, args: [], kwargs: {}, id: nil, anonymous: false)
|
8
|
+
@klass = klass
|
9
|
+
@args = args
|
10
|
+
@kwargs = kwargs
|
11
|
+
@calls = []
|
12
|
+
@tags = []
|
13
|
+
@id = id
|
14
|
+
@anonymous = anonymous
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [Hash] context
|
18
|
+
# @return [Definition]
|
19
|
+
def exec(context: {}, &block)
|
20
|
+
if context.is_a?(Hash)
|
21
|
+
context = OpenStruct.new(context)
|
22
|
+
end
|
23
|
+
|
24
|
+
instance_exec(context, &block)
|
25
|
+
|
26
|
+
Definition.new(@klass, args: @args, kwargs: @kwargs, calls: @calls, tags: @tags, id: @id, anonymous: @anonymous)
|
27
|
+
end
|
28
|
+
|
29
|
+
def args(*arguments, **kv_arguments)
|
30
|
+
@args = arguments
|
31
|
+
@kwargs = kv_arguments
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [String] name
|
35
|
+
def call(name, *arguments, **kv_arguments)
|
36
|
+
@calls << [name, arguments, kv_arguments]
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [String] id
|
40
|
+
def id(id)
|
41
|
+
@anonymous = false
|
42
|
+
@id = id
|
43
|
+
end
|
44
|
+
|
45
|
+
def anonymous!
|
46
|
+
@anonymous = true
|
47
|
+
@id = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param [Class, #to_s] key
|
51
|
+
# @return [Token::ParameterToken]
|
52
|
+
def param(key)
|
53
|
+
Token::ParameterToken.new(key: key)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [String] tag
|
57
|
+
def tag(tag)
|
58
|
+
@tags << tag
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Token::ServiceCallToken]
|
62
|
+
def on(id)
|
63
|
+
Token::ServiceCallToken.new(service: id)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Token::ValueToken]
|
67
|
+
def value(val)
|
68
|
+
Token::ValueToken.new(value: val)
|
69
|
+
end
|
70
|
+
|
71
|
+
# @param [String] tag
|
72
|
+
# @return [Token::TaggedToken]
|
73
|
+
def tagged(tag)
|
74
|
+
Token::TaggedToken.new(tag)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Injectable
|
6
|
+
def definition
|
7
|
+
Definition.new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
refine Class do
|
11
|
+
def injectable(*args, **kwargs, &block)
|
12
|
+
include Injectable
|
13
|
+
|
14
|
+
define_singleton_method :definition do
|
15
|
+
if block.nil?
|
16
|
+
Definition.new(self, args: args, kwargs: kwargs)
|
17
|
+
else
|
18
|
+
Dsl.new(self).exec(&block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
class Injector
|
6
|
+
# @return [Container]
|
7
|
+
attr_reader :container
|
8
|
+
|
9
|
+
# @param [Container] container
|
10
|
+
def initialize(container:)
|
11
|
+
@container = container
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [Object] value
|
15
|
+
def resolve(value)
|
16
|
+
if value.is_a?(Array)
|
17
|
+
value.map(&method(:resolve))
|
18
|
+
elsif value.is_a?(Hash)
|
19
|
+
value.transform_values(&method(:resolve))
|
20
|
+
elsif value.is_a?(Token::InjectionToken)
|
21
|
+
value.resolve(injector: self)
|
22
|
+
else
|
23
|
+
container.get(value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Token
|
6
|
+
class ParameterToken < InjectionToken
|
7
|
+
attr_reader :key
|
8
|
+
|
9
|
+
def initialize(key:)
|
10
|
+
super()
|
11
|
+
|
12
|
+
@key = key
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [Injector] injector
|
16
|
+
def resolve(injector:)
|
17
|
+
injector.container.parameter(key)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Token
|
6
|
+
class ServiceCallToken < InjectionToken
|
7
|
+
attr_reader :service
|
8
|
+
attr_reader :method
|
9
|
+
attr_reader :args
|
10
|
+
attr_reader :kwargs
|
11
|
+
|
12
|
+
def initialize(service:)
|
13
|
+
super()
|
14
|
+
|
15
|
+
@service = service
|
16
|
+
@args = []
|
17
|
+
@kwargs = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(method, *args, **kwargs)
|
21
|
+
@method = method
|
22
|
+
@args = args
|
23
|
+
@kwargs = kwargs
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param [Injector] injector
|
29
|
+
def resolve(injector:)
|
30
|
+
do_call(
|
31
|
+
injector.resolve(service),
|
32
|
+
method,
|
33
|
+
injector.resolve(args),
|
34
|
+
injector.resolve(kwargs)
|
35
|
+
)
|
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
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Token
|
6
|
+
class TaggedToken < InjectionToken
|
7
|
+
# @return [String] tag
|
8
|
+
attr_reader :tag
|
9
|
+
|
10
|
+
# @param [String] tag
|
11
|
+
def initialize(tag)
|
12
|
+
super()
|
13
|
+
|
14
|
+
@tag = tag
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [Injector] injector
|
18
|
+
def resolve(injector:)
|
19
|
+
injector.container.tagged(tag).map { |id| injector.resolve(id) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Token
|
6
|
+
class ValueToken < InjectionToken
|
7
|
+
attr_reader :value
|
8
|
+
|
9
|
+
# @param [Object] value
|
10
|
+
def initialize(value:)
|
11
|
+
super()
|
12
|
+
|
13
|
+
@value = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def resolve(*)
|
17
|
+
@value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Ext
|
5
|
+
module Guards
|
6
|
+
refine Object do
|
7
|
+
def unimplemented!(message = nil)
|
8
|
+
raise Error.new(message || "This method is not implemented.")
|
9
|
+
end
|
10
|
+
|
11
|
+
def unreachable!(message = nil)
|
12
|
+
raise Error.new(message || "Reached unreachable code.")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
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,22 @@
|
|
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
|
+
# @return [Boolean]
|
17
|
+
def failure?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module Result
|
5
|
+
class Result
|
6
|
+
# @return [Boolean]
|
7
|
+
def success?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Boolean]
|
12
|
+
def failure?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
# @yieldparam [Object] value
|
17
|
+
# @yieldreturn [Result]
|
18
|
+
# @return [Result]
|
19
|
+
def and_then(&_block)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
def and_then(&block)
|
22
|
+
retval = block.call(value)
|
23
|
+
|
24
|
+
if retval.is_a?(Result)
|
25
|
+
retval
|
26
|
+
else
|
27
|
+
Failure.new(Errors::BadReturnTypeError.new(retval))
|
28
|
+
end
|
29
|
+
rescue StandardError => error
|
30
|
+
Failure.new(error)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/corindon/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corindon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
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: 2020-
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: semantic
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: zeitwerk
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +38,20 @@ dependencies:
|
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '2.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: minitest
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,7 +88,31 @@ extra_rdoc_files: []
|
|
60
88
|
files:
|
61
89
|
- corindon.gemspec
|
62
90
|
- lib/corindon.rb
|
63
|
-
- lib/corindon/
|
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
|
+
- lib/corindon/dependency_injection/container.rb
|
96
|
+
- lib/corindon/dependency_injection/definition.rb
|
97
|
+
- 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
|
+
- lib/corindon/dependency_injection/injectable.rb
|
101
|
+
- lib/corindon/dependency_injection/injector.rb
|
102
|
+
- lib/corindon/dependency_injection/token/injection_token.rb
|
103
|
+
- lib/corindon/dependency_injection/token/parameter_token.rb
|
104
|
+
- lib/corindon/dependency_injection/token/service_call_token.rb
|
105
|
+
- lib/corindon/dependency_injection/token/tagged_token.rb
|
106
|
+
- lib/corindon/dependency_injection/token/value_token.rb
|
107
|
+
- lib/corindon/ext/guards.rb
|
108
|
+
- lib/corindon/ext/guards/error.rb
|
109
|
+
- lib/corindon/result/errors/bad_return_type_error.rb
|
110
|
+
- lib/corindon/result/errors/result_error.rb
|
111
|
+
- lib/corindon/result/ext.rb
|
112
|
+
- lib/corindon/result/failure.rb
|
113
|
+
- lib/corindon/result/result.rb
|
114
|
+
- lib/corindon/result/success.rb
|
115
|
+
- lib/corindon/something/ext.rb
|
64
116
|
- lib/corindon/version.rb
|
65
117
|
homepage: https://gitlab.com/piotaixr/corindon
|
66
118
|
licenses:
|