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,29 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class ExposeField < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
attribute :from, Symbol
|
8
|
+
attribute :as, Symbol
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(exchange)
|
12
|
+
from_value = exchange.context_fetch(from)
|
13
|
+
|
14
|
+
if from_value.is_a?(Hash)
|
15
|
+
field_value = from_value[field]
|
16
|
+
else
|
17
|
+
if !from_value.respond_to?(field)
|
18
|
+
raise ArgumentError, "#{from} does not respond to #{field}"
|
19
|
+
end
|
20
|
+
|
21
|
+
field_value = from_value.public_send(field)
|
22
|
+
end
|
23
|
+
|
24
|
+
exchange.update_context(as => field_value)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class ExposeFields < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :fields, [Symbol]
|
7
|
+
attribute :from, Symbol
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(exchange)
|
11
|
+
from_value = exchange.context_fetch(from)
|
12
|
+
|
13
|
+
if from_value.is_a?(Hash)
|
14
|
+
field_values = map_hash(from_value)
|
15
|
+
else
|
16
|
+
field_values = map_object(from_value)
|
17
|
+
end
|
18
|
+
|
19
|
+
exchange.update_context(field_values || {})
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def map_hash(from_value)
|
25
|
+
fields.map{|field| {field => from_value[field]}}.reduce(&:merge)
|
26
|
+
end
|
27
|
+
|
28
|
+
def map_object(from_value)
|
29
|
+
fields.map{|field| {field => from_value.public_send(field)}}.reduce(&:merge)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class ExtractResult < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :from, Symbol
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(exchange)
|
10
|
+
result = exchange.context_fetch(from)
|
11
|
+
|
12
|
+
unless result.kind_of?(MiniCamel::Dto) || result.kind_of?(Hash)
|
13
|
+
raise ArgumentError, "Extracted result is not a DTO or a hash!"
|
14
|
+
end
|
15
|
+
|
16
|
+
exchange_result = ExchangeResult.new(result)
|
17
|
+
exchange.set_result(exchange_result)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class Mutate < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
attribute :with_class, Class
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(exchange)
|
11
|
+
mutation = with_class.new(field => exchange.context_fetch(field)).call
|
12
|
+
exchange.update_context(field => mutation)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class MutateEach < ProcessEach
|
4
|
+
|
5
|
+
def call(exchange)
|
6
|
+
additional_data = fetch_additional_data(exchange)
|
7
|
+
|
8
|
+
fetch_collection(exchange).map! do |entry|
|
9
|
+
process(entry, additional_data)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class Process < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :fields, [Symbol]
|
7
|
+
attribute :with_class, Class
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(exchange)
|
11
|
+
with_class.new(visible_fields(exchange)).call
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def visible_fields(exchange)
|
17
|
+
fields.map{|f| {f => exchange.context_fetch(f)}}.reduce(&:merge)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class ProcessEach < Each
|
4
|
+
|
5
|
+
def call(exchange)
|
6
|
+
additional_data = fetch_additional_data(exchange)
|
7
|
+
|
8
|
+
# The use of map is no coincidence! (will be used as result in TransformEach)
|
9
|
+
fetch_collection(exchange).map do |entry|
|
10
|
+
process(entry, additional_data)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class Produce < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
attribute :with_class, Class
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(exchange)
|
11
|
+
exchange.update_context(field => with_class.new.call)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class Validate < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
|
8
|
+
attribute :message, String
|
9
|
+
|
10
|
+
attribute :raise_error, Class
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(exchange)
|
14
|
+
value = exchange.context_fetch(field)
|
15
|
+
raise raise_error.new(message, value) if value.invalid?
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module Processor
|
3
|
+
class WrapInDto < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
attribute :as, Symbol
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(exchange)
|
11
|
+
exchange.update_context(as => MiniCamel::Dto.new(field => exchange.context_fetch(field)))
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class Each < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
validates :field, presence: true
|
8
|
+
|
9
|
+
attribute :in_field, Symbol
|
10
|
+
validates :in_field, presence: true
|
11
|
+
|
12
|
+
attribute :additional_fields, [Symbol]
|
13
|
+
|
14
|
+
attribute :with_class, Class
|
15
|
+
validates :with_class, presence: true
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class ExposeField < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :field, Symbol
|
7
|
+
validates :field, presence: true
|
8
|
+
|
9
|
+
attribute :from, Symbol
|
10
|
+
validates :from, presence: true
|
11
|
+
|
12
|
+
attribute :as, Symbol, default: :default_as
|
13
|
+
validates :as, presence: true
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_processor(env)
|
17
|
+
Processor::ExposeField.new(env: env, field: field, from: from, as: as)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def default_as
|
23
|
+
field
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class ExposeFields < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :fields, [Symbol]
|
7
|
+
validates :fields, presence: true
|
8
|
+
|
9
|
+
attribute :from, Symbol
|
10
|
+
validates :from, presence: true
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_processor(env)
|
14
|
+
Processor::ExposeFields.new(env: env, fields: fields, from: from)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class ExtractResult < Base
|
4
|
+
|
5
|
+
values do
|
6
|
+
attribute :from, Symbol
|
7
|
+
validates :from, presence: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_processor(env)
|
11
|
+
Processor::ExtractResult.new(env: env, from: from)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class Mutate < 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
|
+
|
14
|
+
def generate_processor(env)
|
15
|
+
Processor::Mutate.new(env: env, field: field, with_class: with_class)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MiniCamel
|
2
|
+
module ProcessorDefinition
|
3
|
+
class MutateEach < Each
|
4
|
+
|
5
|
+
def generate_processor(env)
|
6
|
+
Processor::MutateEach.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
|
15
|
+
|