mini_camel 0.5.8
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +4 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.md +22 -0
- data/README.md +300 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/hello_world.rb +106 -0
- data/lib/mini_camel.rb +63 -0
- data/lib/mini_camel/context.rb +5 -0
- data/lib/mini_camel/default_error_handler.rb +37 -0
- data/lib/mini_camel/dto.rb +55 -0
- data/lib/mini_camel/environment.rb +66 -0
- data/lib/mini_camel/error.rb +57 -0
- data/lib/mini_camel/exchange.rb +80 -0
- data/lib/mini_camel/exchange_error.rb +36 -0
- data/lib/mini_camel/exchange_result.rb +5 -0
- data/lib/mini_camel/interactor.rb +13 -0
- data/lib/mini_camel/processor/base.rb +14 -0
- data/lib/mini_camel/processor/each.rb +28 -0
- data/lib/mini_camel/processor/expose_field.rb +29 -0
- data/lib/mini_camel/processor/expose_fields.rb +34 -0
- data/lib/mini_camel/processor/extract_result.rb +22 -0
- data/lib/mini_camel/processor/mutate.rb +18 -0
- data/lib/mini_camel/processor/mutate_each.rb +16 -0
- data/lib/mini_camel/processor/pipeline.rb +19 -0
- data/lib/mini_camel/processor/process.rb +22 -0
- data/lib/mini_camel/processor/process_each.rb +16 -0
- data/lib/mini_camel/processor/produce.rb +17 -0
- data/lib/mini_camel/processor/to.rb +15 -0
- data/lib/mini_camel/processor/transform.rb +15 -0
- data/lib/mini_camel/processor/transform_each.rb +15 -0
- data/lib/mini_camel/processor/validate.rb +21 -0
- data/lib/mini_camel/processor/wrap_in_dto.rb +19 -0
- data/lib/mini_camel/processor_definition/base.rb +13 -0
- data/lib/mini_camel/processor_definition/each.rb +20 -0
- data/lib/mini_camel/processor_definition/expose_field.rb +28 -0
- data/lib/mini_camel/processor_definition/expose_fields.rb +19 -0
- data/lib/mini_camel/processor_definition/extract_result.rb +17 -0
- data/lib/mini_camel/processor_definition/mutate.rb +21 -0
- data/lib/mini_camel/processor_definition/mutate_each.rb +15 -0
- data/lib/mini_camel/processor_definition/pipeline.rb +17 -0
- data/lib/mini_camel/processor_definition/process.rb +19 -0
- data/lib/mini_camel/processor_definition/process_each.rb +14 -0
- data/lib/mini_camel/processor_definition/produce.rb +20 -0
- data/lib/mini_camel/processor_definition/to.rb +17 -0
- data/lib/mini_camel/processor_definition/transform.rb +17 -0
- data/lib/mini_camel/processor_definition/transform_each.rb +20 -0
- data/lib/mini_camel/processor_definition/validate.rb +26 -0
- data/lib/mini_camel/processor_definition/wrap_in_dto.rb +21 -0
- data/lib/mini_camel/route.rb +21 -0
- data/lib/mini_camel/route_builder.rb +24 -0
- data/lib/mini_camel/route_collection.rb +16 -0
- data/lib/mini_camel/route_definition.rb +146 -0
- data/lib/mini_camel/route_dispatcher.rb +37 -0
- data/lib/mini_camel/route_finalizer.rb +38 -0
- data/lib/mini_camel/route_generator.rb +32 -0
- data/lib/mini_camel/strict_dto.rb +36 -0
- data/lib/mini_camel/version.rb +3 -0
- data/mini_camel.gemspec +30 -0
- metadata +237 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class Pipeline < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :routes, [Symbol]
|
7
|
+
validates :routes, presence: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_processor(env)
|
11
|
+
Processor::Pipeline.new(env: env, routes: routes)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class Process < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :fields, [Symbol]
|
7
|
+
validates :fields, presence: true
|
8
|
+
|
9
|
+
attribute :with_class, Class
|
10
|
+
validates :with_class, presence: true
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_processor(env)
|
14
|
+
Processor::Process.new(env: env, fields: fields, with_class: with_class)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class ProcessEach < Each
|
4
|
+
|
5
|
+
def generate_processor(env)
|
6
|
+
Processor::ProcessEach.new(
|
7
|
+
env: env, field: field, in_field: in_field, with_class: with_class,
|
8
|
+
additional_fields: additional_fields
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class Produce < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
validates :field, presence: true
|
8
|
+
|
9
|
+
attribute :with_class, Class
|
10
|
+
validates :with_class, presence: true
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_processor(env)
|
14
|
+
Processor::Produce.new(env: env, field: field, with_class: with_class)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class To < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :route, Symbol
|
7
|
+
validates :route, presence: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_processor(env)
|
11
|
+
Processor::To.new(env: env, route: route)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class Transform < Process
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :to, Symbol
|
7
|
+
validates :to, presence: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_processor(env)
|
11
|
+
Processor::Transform.new(env: env, fields: fields, to: to, with_class: with_class)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class TransformEach < ProcessEach
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :to, Symbol
|
7
|
+
validates :to, presence: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_processor(env)
|
11
|
+
Processor::TransformEach.new(
|
12
|
+
env: env, field: field, in_field: in_field, with_class: with_class,
|
13
|
+
additional_fields: additional_fields, to: to
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class Validate < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
validates :field, presence: true
|
8
|
+
|
9
|
+
attribute :message, String
|
10
|
+
validates :message, presence: true
|
11
|
+
|
12
|
+
attribute :raise_error, Class
|
13
|
+
validates :raise_error, presence: true
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_processor(env)
|
17
|
+
Processor::Validate.new(env: env, field: field, message: message, raise_error: raise_error)
|
18
|
+
end
|
19
|
+
|
20
|
+
def message
|
21
|
+
@message ||= "'#{field}' is invalid."
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class WrapInDto < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
validates :field, presence: true
|
8
|
+
|
9
|
+
attribute :as, Symbol
|
10
|
+
validates :as, presence: true
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_processor(env)
|
14
|
+
Processor::WrapInDto.new(env: env, field: field, as: as)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
class Route
|
3
|
+
include Virtus.value_object
|
4
|
+
|
5
|
+
attribute :env, Environment
|
6
|
+
|
7
|
+
values do
|
8
|
+
attribute :route_name, Symbol
|
9
|
+
attribute :processors, Array, default: []
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(exchange)
|
13
|
+
raise EnvironmentNotFinalized, "Please finalize the environment." unless env.finalized?
|
14
|
+
|
15
|
+
processors.each do |processor|
|
16
|
+
processor.call(exchange)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
class RouteBuilder
|
3
|
+
include Virtus.value_object
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :route_collection
|
7
|
+
end
|
8
|
+
|
9
|
+
def configure
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
def route_collection
|
14
|
+
@route_collection ||= RouteCollection.new
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def from(route_name)
|
20
|
+
route_collection.from(route_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
class RouteCollection
|
3
|
+
include Virtus.value_object
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :routes, Array, default: []
|
7
|
+
end
|
8
|
+
|
9
|
+
def from(route_name)
|
10
|
+
route_definition = RouteDefinition.new(route_name: route_name)
|
11
|
+
routes << route_definition
|
12
|
+
route_definition
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
class RouteDefinition
|
3
|
+
include Virtus.value_object
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
values do
|
7
|
+
attribute :route_name, Symbol
|
8
|
+
validates :route_name, presence: true
|
9
|
+
|
10
|
+
attribute :description, String
|
11
|
+
validates :description, presence: true
|
12
|
+
|
13
|
+
attribute :processor_definitions, Array, default: []
|
14
|
+
validates :processor_definitions, presence: true
|
15
|
+
end
|
16
|
+
|
17
|
+
def from(route_name)
|
18
|
+
self.route_name = route_name
|
19
|
+
end
|
20
|
+
|
21
|
+
def desc(description)
|
22
|
+
self.description = description
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def to(route)
|
27
|
+
definition = ProcessorDefinition::To.new(route: route)
|
28
|
+
|
29
|
+
add_processor_definition(definition)
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def pipeline(*routes)
|
35
|
+
definition = ProcessorDefinition::Pipeline.new(routes: routes)
|
36
|
+
|
37
|
+
add_processor_definition(definition)
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def process(*fields, **options)
|
43
|
+
definition = ProcessorDefinition::Process.new(options.merge(fields: fields))
|
44
|
+
|
45
|
+
add_processor_definition(definition)
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_each(field, **options)
|
51
|
+
options[:in_field] = options.delete(:in)
|
52
|
+
definition = ProcessorDefinition::ProcessEach.new(options.merge(field: field))
|
53
|
+
|
54
|
+
add_processor_definition(definition)
|
55
|
+
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def transform(*fields, **options)
|
60
|
+
definition = ProcessorDefinition::Transform.new(options.merge(fields: fields))
|
61
|
+
|
62
|
+
add_processor_definition(definition)
|
63
|
+
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def transform_each(field, **options)
|
68
|
+
options[:in_field] = options.delete(:in)
|
69
|
+
definition = ProcessorDefinition::TransformEach.new(options.merge(field: field))
|
70
|
+
|
71
|
+
add_processor_definition(definition)
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def mutate(field, **options)
|
77
|
+
definition = ProcessorDefinition::Mutate.new(options.merge(field: field))
|
78
|
+
|
79
|
+
add_processor_definition(definition)
|
80
|
+
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
def mutate_each(field, **options)
|
85
|
+
options[:in_field] = options.delete(:in)
|
86
|
+
definition = ProcessorDefinition::MutateEach.new(options.merge(field: field))
|
87
|
+
|
88
|
+
add_processor_definition(definition)
|
89
|
+
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def produce(field, **options)
|
94
|
+
definition = ProcessorDefinition::Produce.new(options.merge(field: field))
|
95
|
+
|
96
|
+
add_processor_definition(definition)
|
97
|
+
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
def expose_field(field, **options)
|
102
|
+
definition = ProcessorDefinition::ExposeField.new(options.merge(field: field))
|
103
|
+
|
104
|
+
add_processor_definition(definition)
|
105
|
+
|
106
|
+
self
|
107
|
+
end
|
108
|
+
|
109
|
+
def expose_fields(*fields, **options)
|
110
|
+
definition = ProcessorDefinition::ExposeFields.new(options.merge(fields: fields))
|
111
|
+
|
112
|
+
add_processor_definition(definition)
|
113
|
+
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def wrap_in_dto(field, **options)
|
118
|
+
definition = ProcessorDefinition::WrapInDto.new(options.merge(field: field))
|
119
|
+
|
120
|
+
add_processor_definition(definition)
|
121
|
+
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
def extract_result(**options)
|
126
|
+
definition = ProcessorDefinition::ExtractResult.new(options)
|
127
|
+
|
128
|
+
add_processor_definition(definition)
|
129
|
+
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
def validate(field, **options)
|
134
|
+
definition = ProcessorDefinition::Validate.new(options.merge(field: field))
|
135
|
+
|
136
|
+
add_processor_definition(definition)
|
137
|
+
|
138
|
+
self
|
139
|
+
end
|
140
|
+
|
141
|
+
def add_processor_definition(processor_definition)
|
142
|
+
processor_definitions << processor_definition
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
class RouteDispatcher
|
3
|
+
include Virtus.value_object
|
4
|
+
|
5
|
+
attribute :env, Environment
|
6
|
+
|
7
|
+
values do
|
8
|
+
attribute :route, Symbol
|
9
|
+
attribute :with_data, Object
|
10
|
+
end
|
11
|
+
|
12
|
+
def dispatch
|
13
|
+
raise EnvironmentNotFinalized, "Please finalize the environment." unless env.finalized?
|
14
|
+
|
15
|
+
exchange = Exchange.new(context: Context.new(with_data))
|
16
|
+
|
17
|
+
env.call_route(route, exchange)
|
18
|
+
|
19
|
+
exchange
|
20
|
+
rescue Exception => error
|
21
|
+
rescue_error(error, exchange)
|
22
|
+
|
23
|
+
exchange
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def rescue_error(error, exchange)
|
29
|
+
error_handler.call(error, exchange)
|
30
|
+
end
|
31
|
+
|
32
|
+
def error_handler
|
33
|
+
env.error_handler
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
class RouteFinalizer
|
3
|
+
include Virtus.value_object
|
4
|
+
|
5
|
+
attribute :env, Environment
|
6
|
+
|
7
|
+
values do
|
8
|
+
attribute :route_generator_class, Class
|
9
|
+
end
|
10
|
+
|
11
|
+
def finalize
|
12
|
+
env.route_builders.each(&:configure)
|
13
|
+
|
14
|
+
route_collections = env.route_builders.map(&:route_collection)
|
15
|
+
|
16
|
+
route_collections.each do |route_collection|
|
17
|
+
route_definitions = route_collection.routes
|
18
|
+
|
19
|
+
route_definitions.each do |route_definition|
|
20
|
+
env.add_route(generate_route(route_definition))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
env.finalized!
|
25
|
+
end
|
26
|
+
|
27
|
+
def route_generator_class
|
28
|
+
@route_generator_class ||= RouteGenerator
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def generate_route(route_definition)
|
34
|
+
route_generator_class.new(env: env, route_definition: route_definition).generate_route
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|