eco-helpers 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eco/api.rb +1 -0
- data/lib/eco/api/common.rb +1 -0
- data/lib/eco/api/common/class_helpers.rb +33 -0
- data/lib/eco/api/common/people.rb +1 -0
- data/lib/eco/api/common/people/person_attribute_parser.rb +52 -0
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +2 -2
- data/lib/eco/api/common/people/person_parser.rb +16 -10
- data/lib/eco/api/common/version_patches.rb +2 -3
- data/lib/eco/api/common/version_patches/ecoportal_api.rb +4 -0
- data/lib/eco/api/common/version_patches/{base_model.rb → ecoportal_api/base_model.rb} +0 -0
- data/lib/eco/api/common/version_patches/{external_person.rb → ecoportal_api/external_person.rb} +0 -0
- data/lib/eco/api/common/version_patches/{internal_person.rb → ecoportal_api/internal_person.rb} +0 -0
- data/lib/eco/api/common/version_patches/hash.rb +2 -0
- data/lib/eco/api/common/version_patches/hash/deep_merge.rb +34 -0
- data/lib/eco/api/error.rb +133 -0
- data/lib/eco/api/error/handler.rb +19 -0
- data/lib/eco/api/error/handlers.rb +22 -0
- data/lib/eco/api/organization/people.rb +11 -11
- data/lib/eco/api/organization/policy_groups.rb +8 -0
- data/lib/eco/api/policies.rb +26 -3
- data/lib/eco/api/policies/policy.rb +4 -5
- data/lib/eco/api/session.rb +27 -18
- data/lib/eco/api/session/batch.rb +12 -6
- data/lib/eco/api/session/batch/errors.rb +134 -0
- data/lib/eco/api/session/batch/job.rb +213 -0
- data/lib/eco/api/session/batch/jobs.rb +72 -0
- data/lib/eco/api/session/batch/jobs_groups.rb +85 -0
- data/lib/eco/api/session/batch/status.rb +133 -0
- data/lib/eco/api/session/config.rb +36 -14
- data/lib/eco/api/session/config/base_config.rb +2 -0
- data/lib/eco/api/session/config/people.rb +8 -0
- data/lib/eco/api/session/config/post_launch.rb +58 -0
- data/lib/eco/api/session/config/workflow.rb +189 -0
- data/lib/eco/api/session/task.rb +49 -6
- data/lib/eco/api/usecases.rb +137 -2
- data/lib/eco/api/usecases/base_case.rb +20 -8
- data/lib/eco/api/usecases/base_io.rb +97 -0
- data/lib/eco/api/usecases/default_case.rb +19 -0
- data/lib/eco/api/usecases/default_cases.rb +2 -2
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/create_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/delete_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/hris_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +11 -8
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -4
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +3 -3
- data/lib/eco/api/usecases/default_cases/update_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +2 -2
- data/lib/eco/api/usecases/use_case.rb +23 -36
- data/lib/eco/api/usecases/use_case_chain.rb +14 -24
- data/lib/eco/api/usecases/use_case_io.rb +23 -75
- data/lib/eco/assets.rb +11 -11
- data/lib/eco/cli.rb +37 -0
- data/lib/eco/cli/config.rb +63 -1
- data/lib/eco/cli/config/default.rb +15 -0
- data/lib/eco/cli/config/default/filters.rb +69 -0
- data/lib/eco/cli/config/default/input.rb +21 -0
- data/lib/eco/cli/config/default/options.rb +47 -0
- data/lib/eco/cli/config/default/people.rb +39 -0
- data/lib/eco/cli/config/default/usecases.rb +63 -0
- data/lib/eco/cli/config/default/workflow.rb +86 -0
- data/lib/eco/cli/config/input.rb +40 -0
- data/lib/eco/cli/config/options_set.rb +35 -0
- data/lib/eco/cli/config/people_filters.rb +38 -0
- data/lib/eco/cli/config/use_cases.rb +87 -0
- data/lib/eco/cli/scripting/args_helpers.rb +10 -4
- data/lib/eco/cli/scripting/argument.rb +6 -0
- data/lib/eco/language/models/collection.rb +1 -0
- data/lib/eco/version.rb +1 -1
- metadata +32 -12
- data/lib/eco/api/policies/base_policy.rb +0 -14
- data/lib/eco/api/policies/used_policies.rb +0 -37
- data/lib/eco/api/session/batch_job.rb +0 -215
- data/lib/eco/api/session/batch_jobs.rb +0 -62
- data/lib/eco/api/session/batch_status.rb +0 -205
- data/lib/eco/api/session/job_groups.rb +0 -75
- data/lib/eco/api/usecases/use_group.rb +0 -124
- data/lib/eco/cli/config/options.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c71b81aaf2b40c4f9388fc87176a3ca7b5cd4c274a760546aaae8e98b00abea5
|
4
|
+
data.tar.gz: cfefc68eed3bfbfd1767ca222bf3c7dfca2d7ce77d94fa6cf5b0b406754ae0aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14234f90a41da5093e8f1af208edc9aea7f454c8f15b8a19dcbbfce63559d3e82b47de850160d3f843d30ab0fac0fc9c44bd3f60a56e056c7b8922f64624da29
|
7
|
+
data.tar.gz: 6c8d9cf5e0311591601be6e1f211c23667b5ea7902e8704edaa53eeb1d3e1123780b0bc7fee44b85d39792e2bbe7cf23c43b5a8dc815db69fc16e5e3daa9fe88
|
data/lib/eco/api.rb
CHANGED
data/lib/eco/api/common.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module ClassHelpers
|
5
|
+
|
6
|
+
def class_resolver(name, klass)
|
7
|
+
define_singleton_method(name) { resolve_class(klass) }
|
8
|
+
define_method(name) { self.class.resolve_class(klass) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def resolve_class(klass, exception: true)
|
12
|
+
@resolved ||= {}
|
13
|
+
@resolved[klass] ||=
|
14
|
+
case klass
|
15
|
+
when Class
|
16
|
+
klass
|
17
|
+
when String
|
18
|
+
begin
|
19
|
+
Kernel.const_get(klass)
|
20
|
+
rescue NameError => e
|
21
|
+
raise e if exception
|
22
|
+
end
|
23
|
+
when Symbol
|
24
|
+
resolve_class(self.send(klass))
|
25
|
+
else
|
26
|
+
raise "Unknown class: #{klass}" if exception
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -10,6 +10,7 @@ end
|
|
10
10
|
require_relative 'people/person_modifier'
|
11
11
|
require_relative 'people/person_factory'
|
12
12
|
require_relative 'people/base_parser'
|
13
|
+
require_relative 'people/person_attribute_parser'
|
13
14
|
require_relative 'people/person_parser'
|
14
15
|
require_relative 'people/default_parsers'
|
15
16
|
require_relative 'people/person_entry_attribute_mapper'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module People
|
5
|
+
|
6
|
+
# Class to define a parser/serializer.
|
7
|
+
class PersonAttributeParser < Eco::Language::Models::ParserSerializer
|
8
|
+
|
9
|
+
# @see Eco::Language::Models::ParserSerializer#def_parser
|
10
|
+
# @note
|
11
|
+
# - additionally, you can declare a callback `active:` to determine if when the
|
12
|
+
# parser will be active/used.
|
13
|
+
# - this is important to help avoiding to set values that are not present in the input entry.
|
14
|
+
# - if you have doubts about using it or not, do not use it.
|
15
|
+
# @param active_when [Proc] that expects a list of internal attributes or the internal entry itself
|
16
|
+
# By default, an attribute paraser is active if in the entry to parse the internal attribute is present.
|
17
|
+
def def_parser(active_when: nil, &block)
|
18
|
+
@active_when = attribute_present(active_when)
|
19
|
+
super(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Determines if for a given source data to parse, this parser should be active or not
|
23
|
+
# @return [Boolean] `true` if there's no callback defined or there is and evaluates `true`
|
24
|
+
# when for the current data to parse. It returns `false` otherwise.
|
25
|
+
def parser_active?(source_data)
|
26
|
+
@active_when.call(source_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# by default, an attribute paraser is active if in the entry to parse
|
32
|
+
# the internal attribute is present
|
33
|
+
def attribute_present(active_when)
|
34
|
+
Proc.new do |source_data|
|
35
|
+
case source_data
|
36
|
+
when Array
|
37
|
+
keys = source_data
|
38
|
+
when Hash
|
39
|
+
keys = source_data.keys
|
40
|
+
else
|
41
|
+
keys = []
|
42
|
+
end
|
43
|
+
|
44
|
+
(source_data && keys.include?(self.attr)) ||
|
45
|
+
(active_when && active_when.call(source_data))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -6,7 +6,7 @@ module Eco
|
|
6
6
|
# @attr_reader core_attrs [Array<String>] core attributes that are present in the person entry.
|
7
7
|
# @attr_reader details_attrs [Array<String>] schema details attributes that are present in the person entry.
|
8
8
|
# @attr_reader account_attrs [Array<String>] account attributes that are present in the person entry.
|
9
|
-
# @attr_reader all_attrs [Array<String>] all the attrs that are present in the person entry.
|
9
|
+
# @attr_reader all_attrs [Array<String>] all the attrs that are present in the person entry.
|
10
10
|
# @attr_reader internal_attrs [Array<String>] all the internally named attributes that the person entry has.
|
11
11
|
# @attr_reader aliased_attrs [Array<String>] only those internal attributes present in the person entry that have an internal/external name mapping.
|
12
12
|
# @attr_reader direct_attrs [Array<String>] only those internal attributes present in the person entry that do **not** have an internal/external name mapping.
|
@@ -23,7 +23,7 @@ module Eco
|
|
23
23
|
# - if `data` is a `Person` object, its behaviour is `serialise`.
|
24
24
|
# - if `data` is **not** a `Person` object, it does a `parse`.
|
25
25
|
# - currently **in rework**, so there may be subtle differences that make it temporarily unstable (yet it is reliable).
|
26
|
-
# @param data [Hash, Person] `Person` object to be serialized or hashed entry (`CSV::Row` is accepted).
|
26
|
+
# @param data [Hash, Person] `Person` object to be serialized or hashed entry (note: `CSV::Row` is accepted).
|
27
27
|
# @param person_parser [Common::People::PersonParser] parser/serializer of person attributes (it contains a set of attribute parsers).
|
28
28
|
# @param attr_map [Eco::Data::Mapper] mapper to translate attribute names from _external_ to _internal_ names and _vice versa_.
|
29
29
|
# @param logger [Common::Session::Logger, ::Logger] object to manage logs.
|
@@ -43,12 +43,6 @@ module Eco
|
|
43
43
|
@all_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
|
44
44
|
end
|
45
45
|
|
46
|
-
# Lists all defined attributes, types and formats.
|
47
|
-
# @return [Array<String>] the list of defined parsers/serializers.
|
48
|
-
def list_defined
|
49
|
-
@parsers.keys
|
50
|
-
end
|
51
|
-
|
52
46
|
# Scopes `source_attrs` using the _**core** attributes_.
|
53
47
|
# @note use this helper to know which among your attributes are **core** ones.
|
54
48
|
# @param source_attrs [Array<String>]
|
@@ -76,14 +70,26 @@ module Eco
|
|
76
70
|
scoped_attrs(source_attrs, ACCOUNT_ATTRS)
|
77
71
|
end
|
78
72
|
|
73
|
+
# Lists all defined attributes, types and formats.
|
74
|
+
# @return [Array<String>] the list of defined parsers/serializers.
|
75
|
+
#def list_defined
|
76
|
+
# @parsers.keys
|
77
|
+
#end
|
78
|
+
|
79
79
|
# Returns a list of all the internal attributes of the model that have a parser defined.
|
80
|
-
# @note it excludes any parser that is not in the model, such as type parsers (i.e.
|
80
|
+
# @note it excludes any parser that is not in the model, such as type parsers (i.e. `:boolean`, `:multiple`)
|
81
81
|
# @return [Array<String>] list of all attribute defined parsers.
|
82
82
|
def defined_attrs
|
83
83
|
defined = @parsers.keys
|
84
84
|
defined - (defined - all_attrs)
|
85
85
|
end
|
86
86
|
|
87
|
+
# Returns a list of all the internal attributes of the model that have a parser defined & that should be active.
|
88
|
+
# @return [Array<String>] list of all attribute defined parsers that should be active.
|
89
|
+
def active_attrs(source_data)
|
90
|
+
defined_attrs.select {|attr| @parsers[attr].parser_active?(source_data)}
|
91
|
+
end
|
92
|
+
|
87
93
|
# Returns a list of all the internal attributes of the model that do **not** have a parser defined.
|
88
94
|
# @note it excludes any parser that is **not** in the model, such as type parsers (i.e. :boolean, :multiple)
|
89
95
|
# @return [Array<String>] list of all attributes without a defined parser.
|
@@ -123,8 +129,8 @@ module Eco
|
|
123
129
|
msg = "The attribute '#{attr_to_str(attr)}' is not part of core, account or target schema, or does not match any type: #{@details_attrs}"
|
124
130
|
raise msg
|
125
131
|
end
|
126
|
-
|
127
|
-
Eco::
|
132
|
+
# Eco::Language::Models::ParserSerializer
|
133
|
+
Eco::API::Common::People::PersonAttributeParser.new(attr, dependencies: dependencies).tap do |parser|
|
128
134
|
@parsers[attr] = parser
|
129
135
|
definition.call(parser)
|
130
136
|
end
|
@@ -169,7 +175,7 @@ module Eco
|
|
169
175
|
|
170
176
|
def scoped_attrs(source_attrs, section_attrs)
|
171
177
|
direct_attrs = source_attrs & section_attrs
|
172
|
-
parsed_attrs =
|
178
|
+
parsed_attrs = active_attrs(source_attrs) & section_attrs
|
173
179
|
(source_attrs + parsed_attrs) & (direct_attrs + parsed_attrs)
|
174
180
|
end
|
175
181
|
|
@@ -7,6 +7,5 @@ module Eco
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
require_relative 'version_patches/
|
11
|
-
require_relative 'version_patches/
|
12
|
-
require_relative 'version_patches/internal_person.rb'
|
10
|
+
require_relative 'version_patches/hash'
|
11
|
+
require_relative 'version_patches/ecoportal_api'
|
File without changes
|
data/lib/eco/api/common/version_patches/{external_person.rb → ecoportal_api/external_person.rb}
RENAMED
File without changes
|
data/lib/eco/api/common/version_patches/{internal_person.rb → ecoportal_api/internal_person.rb}
RENAMED
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Hash
|
2
|
+
# Source: `ActiveSupport`
|
3
|
+
# - https://github.com/rails/rails/blob/b2eb1d1c55a59fee1e6c4cba7030d8ceb524267c/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
4
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
5
|
+
#
|
6
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
7
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
8
|
+
#
|
9
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
10
|
+
#
|
11
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
12
|
+
# to merge values:
|
13
|
+
#
|
14
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
15
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
16
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
17
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
18
|
+
def deep_merge(other_hash, &block)
|
19
|
+
dup.deep_merge!(other_hash, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Same as +deep_merge+, but modifies +self+.
|
23
|
+
def deep_merge!(other_hash, &block)
|
24
|
+
merge!(other_hash) do |key, this_val, other_val|
|
25
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
26
|
+
this_val.deep_merge(other_val, &block)
|
27
|
+
elsif block_given?
|
28
|
+
block.call(key, this_val, other_val)
|
29
|
+
else
|
30
|
+
other_val
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Error < Exception
|
4
|
+
class UnknownErrorClass < Exception
|
5
|
+
def initialize(msg = nil, klass:)
|
6
|
+
msg ||= "Unkown api error class #{klass}"
|
7
|
+
super(msg)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
@str_err = "api error on the server reply"
|
12
|
+
@match = /.*/
|
13
|
+
#RxValidId = /[a-f0-9]{24}/
|
14
|
+
|
15
|
+
class Unclassified < Eco::API::Error
|
16
|
+
@str_error = "Unclassified error message"
|
17
|
+
@match = /.*/
|
18
|
+
end
|
19
|
+
|
20
|
+
class UnknownPersonId < Eco::API::Error
|
21
|
+
@str_err = "Unknown person id"
|
22
|
+
@match = /Cannot find person with id (.*)/
|
23
|
+
end
|
24
|
+
class EmailMissing < Eco::API::Error
|
25
|
+
@str_err = "missing email for account creation"
|
26
|
+
@match = /#{@str_err}/
|
27
|
+
end
|
28
|
+
class EmailInvalid < Eco::API::Error
|
29
|
+
@str_err = "Email is invalid"
|
30
|
+
@match = /#{@str_err}/
|
31
|
+
end
|
32
|
+
class EmailTaken < Eco::API::Error
|
33
|
+
@str_err = "user email already taken"
|
34
|
+
@match = /#{@str_err}/
|
35
|
+
end
|
36
|
+
class SupervisorNotFound < Eco::API::Error
|
37
|
+
@str_err = "Supervisor not found"
|
38
|
+
@match = /Supervisor (.*?) not found/
|
39
|
+
end
|
40
|
+
class CyclicSupervisor < Eco::API::Error
|
41
|
+
@str_err = "Supervisor is cyclic!"
|
42
|
+
@match = /#{@str_err}/
|
43
|
+
end
|
44
|
+
class SchemaNotFound < Eco::API::Error
|
45
|
+
@str_err = "Schema not found"
|
46
|
+
@match = /Schema (.*?) not found/
|
47
|
+
end
|
48
|
+
class InvalidObjectId < Eco::API::Error
|
49
|
+
@str_err = "Invalid ObjectId."
|
50
|
+
@match = /'(.*?)' is an invalid ObjectId./
|
51
|
+
end
|
52
|
+
class UnkownField < Eco::API::Error
|
53
|
+
@str_err = "Unknown field."
|
54
|
+
@match = /(.+?) is an unknown field/
|
55
|
+
|
56
|
+
class UnkownCoreField < UnkownField
|
57
|
+
@str_err = "Unknown core field."
|
58
|
+
@match = /(.+?) is an unknown field/
|
59
|
+
end
|
60
|
+
class UnkownAccountField < UnkownField
|
61
|
+
@str_err = "Unknown account field."
|
62
|
+
@match = /account \> (.+?) is an unknown field/
|
63
|
+
end
|
64
|
+
class UnkownDetailsField < UnkownField
|
65
|
+
@str_err = "Unknown details field."
|
66
|
+
@match = /details \> (.+?) is an unknown field/
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
def descendants(direct: false)
|
73
|
+
ObjectSpace.each_object(::Class).select do |klass|
|
74
|
+
klass < self
|
75
|
+
end.tap do |siblings|
|
76
|
+
if direct
|
77
|
+
siblings.reject! do |si|
|
78
|
+
siblings.any? {|s| si < s}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def descendants?(direct: false)
|
85
|
+
descendants(direct: direct).length > 0
|
86
|
+
end
|
87
|
+
|
88
|
+
def err_match?(err_msg)
|
89
|
+
err_msg =~ @match
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_type(err_msg)
|
93
|
+
type = nil
|
94
|
+
descendants(direct: true).reverse.each do |klass|
|
95
|
+
if klass.err_match?(err_msg)
|
96
|
+
type = klass
|
97
|
+
if klass.descendants?(direct: true)
|
98
|
+
type = klass.get_type(err_msg) || type
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
type
|
103
|
+
end
|
104
|
+
|
105
|
+
def known_err_class?(klass)
|
106
|
+
descendants.push(self).include?(klass)
|
107
|
+
end
|
108
|
+
|
109
|
+
def validate_err_class(klass)
|
110
|
+
raise UnknownErrorClass.new(klass: klass) unless known_err_class?(klass)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
attr_reader :msg, :err_msg, :session, :entry
|
115
|
+
|
116
|
+
def initialize(msg = nil, err_msg:, session: nil, entry: nil)
|
117
|
+
@msg = msg
|
118
|
+
@err_msg = err_msg
|
119
|
+
@session = session
|
120
|
+
@entry = entry
|
121
|
+
|
122
|
+
super(built_error)
|
123
|
+
end
|
124
|
+
|
125
|
+
def built_error
|
126
|
+
str ||= msg
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
require_relative 'error/handler'
|
133
|
+
require_relative 'error/handlers'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Error
|
4
|
+
class Handler < Eco::API::UseCases::UseCase
|
5
|
+
@types = [:transform]
|
6
|
+
|
7
|
+
def initialize(name, type: :transform, root:, &block)
|
8
|
+
super(name, type: type, root: root, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def root=(value)
|
12
|
+
raise "Root should be a Eco::API::Error::Handlers object. Given: #{value}" if !value.is_a?(Eco::API::Error::Handlers)
|
13
|
+
@root = value
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class Error
|
4
|
+
class Handlers < Eco::API::UseCases
|
5
|
+
|
6
|
+
def add(handler)
|
7
|
+
raise "Expected Eco::API::Error::Handler object. Given: #{policy}" unless handler.is_a?(Eco::API::Error::Handler)
|
8
|
+
super(handler)
|
9
|
+
end
|
10
|
+
|
11
|
+
def on(klass_err, type: :transform, retry: true, &block)
|
12
|
+
Eco::API::Error.validate_err_class(klass_err)
|
13
|
+
raise "Expected block but not given" unless block
|
14
|
+
Eco::API::Error::Handler.new(klass_err, type: type, root: self, &block).tap do |handler|
|
15
|
+
add(handler)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|