eco-helpers 2.6.0 → 2.6.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/CHANGELOG.md +91 -1
- data/README.md +5 -0
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/class_helpers.rb +1 -1
- data/lib/eco/api/common/loaders/base.rb +5 -0
- data/lib/eco/api/common/loaders/case_base.rb +0 -2
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +78 -0
- data/lib/eco/api/common/loaders/config/workflow.rb +11 -0
- data/lib/eco/api/common/loaders/config.rb +29 -0
- data/lib/eco/api/common/loaders/error_handler.rb +0 -2
- data/lib/eco/api/common/loaders/parser.rb +0 -1
- data/lib/eco/api/common/loaders/policy.rb +0 -2
- data/lib/eco/api/common/loaders.rb +1 -0
- data/lib/eco/api/common/session/mailer.rb +3 -1
- data/lib/eco/api/common/version_patches/exception.rb +2 -2
- data/lib/eco/api/common/version_patches/ruby3/object.rb +18 -0
- data/lib/eco/api/common/version_patches/ruby3.rb +1 -0
- data/lib/eco/api/common/version_patches.rb +3 -0
- data/lib/eco/api/custom/config.rb +10 -0
- data/lib/eco/api/custom/mailer.rb +9 -0
- data/lib/eco/api/custom/namespace.rb +2 -0
- data/lib/eco/api/custom/workflow.rb +9 -0
- data/lib/eco/api/custom.rb +3 -0
- data/lib/eco/api/session/batch/base_policy.rb +13 -5
- data/lib/eco/api/session/batch/job.rb +10 -7
- data/lib/eco/api/session/config/tagtree.rb +15 -1
- data/lib/eco/api/session/config/workflow.rb +94 -58
- data/lib/eco/api/session/config.rb +2 -2
- data/lib/eco/api/usecases/base_io.rb +50 -4
- data/lib/eco/api/usecases/cli/dsl.rb +23 -13
- data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +5 -0
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +12 -4
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +1 -2
- data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +62 -0
- data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +59 -0
- data/lib/eco/api/usecases/ooze_samples/helpers.rb +2 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +2 -1
- data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +2 -26
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +64 -47
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -0
- data/lib/eco/api/usecases/use_case.rb +12 -2
- data/lib/eco/assets.rb +2 -2
- data/lib/eco/cli_default/workflow.rb +102 -120
- data/lib/eco/data/locations/node_base/tag_validations.rb +19 -9
- data/lib/eco/data/locations/node_base/treeify.rb +193 -18
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +11 -9
- data/lib/eco/data/locations/node_diff/selectors.rb +1 -1
- data/lib/eco/data/locations/node_level.rb +1 -1
- data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
- data/lib/eco/data/locations/node_plain/serial.rb +1 -1
- data/lib/eco/data/locations/node_plain.rb +4 -3
- data/lib/eco/language/klass/when_inherited.rb +17 -0
- data/lib/eco/language/klass.rb +8 -0
- data/lib/eco/language/methods/delegate_missing.rb +28 -0
- data/lib/eco/language/methods/dsl_able.rb +25 -0
- data/lib/eco/language/methods.rb +9 -0
- data/lib/eco/language.rb +2 -0
- data/lib/eco/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0904af2dd434adc72c1ca3e889d4e0b11595ce991f6de1c997f613d80c8866ce'
|
4
|
+
data.tar.gz: b21748a878327830d5c813340ab2fcfe69ebace8137480bc9dfc42f290296cbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bccc140b8ec44d41aaccdffde8e5b51a1c755fc75dcede5e08526be6daed4482a5f733ceba6a75155f1dee74dbc8e2edc52ee9f2ab55f7ebf6521acfd3aac47
|
7
|
+
data.tar.gz: b362a14bf0a872ee04928ace6c05600df37ecfd56cb754b5f2a0cc3a417115cc8d9a889ce5f40de80ed41f281b16005eed78eadf04a330dc6fa80066baa56e63
|
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,106 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [2.6.
|
4
|
+
## [2.6.2] - 2024-02-23
|
5
5
|
|
6
6
|
### Added
|
7
|
+
- `Eco::API::Session::Config::TagTree`: added **benchmarks** to locations structure live retrieval
|
8
|
+
- To all **Ooze** cases that use register update
|
9
|
+
- `Eco::API::UseCases::OozeSamples::Helpers::Creatable` native helpers
|
10
|
+
- to draft entries
|
11
|
+
- `Eco::API::UseCases::OozeSamples::RegisterMigrationCase` -> removed code double-up due to this addition to the register update case.
|
12
|
+
- `Eco::API::Common::Loaders::Base` added **methods**
|
13
|
+
- `#simulate?` and `#dry_run?`
|
14
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
|
15
|
+
- added **kpis** attempted updates and attempted creations
|
16
|
+
|
7
17
|
### Changed
|
18
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
|
19
|
+
- `#main` allows to tell it to just `yield`
|
20
|
+
|
8
21
|
### Fixed
|
22
|
+
- `Eco::Data::Locations::NodeDiff::Selectors` `any?` (typo)
|
23
|
+
- `Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase`
|
24
|
+
- fixed **kpis** tracking
|
25
|
+
|
26
|
+
## [2.6.1] - 2024-02-11
|
9
27
|
|
28
|
+
### Added
|
29
|
+
- For use case `Eco::API::UseCases::Default::Locations::TagtreeExtract`
|
30
|
+
- New `-indent` option
|
31
|
+
- `Eco::API::UseCases::UseCase`
|
32
|
+
- Defines on loader object attr reader methods `people`, `input` and `usecase` unless they already exist.
|
33
|
+
- Some class / method helpers
|
34
|
+
- `Eco::Language::Methods::DelegateMissing` to redirect missing methods to one object
|
35
|
+
- `Eco::Language::Methods::DslAble` to allow direct method calls on blocks
|
36
|
+
- `Eco::Language::Klass:WhenInherited` to allow to defined a block that gets called when the class is inherited
|
37
|
+
- **DSL** capabilities (for block calls) for
|
38
|
+
- `Eco::API::Session::Batch::BasePolicy`
|
39
|
+
- `Eco::API::Session::Batch::Job`
|
40
|
+
- `api_excluded` block to be called in the Job's context
|
41
|
+
- `Eco::API::UseCases::BaseIO`
|
42
|
+
- This shortens code lines in workflow blocks
|
43
|
+
- `Eco::API::Session::Config::Workflow#run` has been adapted to boost the evalution of the workflow blocks within the context of the `BaseIO` that is carried throughout all the run process.
|
44
|
+
- **NEW** Loaders
|
45
|
+
- `Eco::API::Custom::Config` (**DSL** alike) allows to open up configuration via class
|
46
|
+
- Redirects to `Eco::API::Common::Loaders::Config`
|
47
|
+
- Re-usable sample child classes can created with the use of `config_block`, which in combination with `when_inherited` will load the basic config to custom config classes.
|
48
|
+
- `Eco::API::Custom::Workflow` (**DSL** alike) allows to open up workflow configurations via class
|
49
|
+
- Redirects to `Eco::API::Common::Loaders::Config::Workflow`
|
50
|
+
- `Eco::API::Custom::Mailer` (first **sample**) allows to just define some constants to modify the generic behaviour of this sample class you will want to inherit to enable mailing workflow.
|
51
|
+
- Redirects to `Eco::API::Common::Loaders::Config::Workflow::Mailer`
|
52
|
+
- `Eco::Assets#cli` able to yield the `cli` to a block
|
53
|
+
- `Eco::API::UseCases::BaseIO#process_case`
|
54
|
+
- **added method** `process_case`, which allows to pass the `io` itself as a paramter.
|
55
|
+
- When this is used, the `output` swap as `input` / `people` is performed (before and after).
|
56
|
+
|
57
|
+
### Changed
|
58
|
+
- **IMPORTANT** overriden `Object#inspect` to `to_s` to prevent recursive deep introspection of object internals on `MethodError`
|
59
|
+
- `Eco::API::Common::Loaders::CaseBase`
|
60
|
+
- **removed** attr `usecase`
|
61
|
+
- `Eco::API::UseCases::BaseIO`
|
62
|
+
- `output` can be set on initialization
|
63
|
+
- `#new` carries the `output` as well.
|
64
|
+
- `Eco::API::Session::Config::Workflow`
|
65
|
+
- `#run`
|
66
|
+
- workflow blocks don't require to explicitly return the `BaseIO` when there isn't any to return. It will just keep the `io` as it was before the call.
|
67
|
+
- also made it so the returned io is **always** an **instance of** `Eco::API::UseCases::BaseIO` (so it won't return an instance of a child class). This change can be considered a fix. **Aside note:** only possible now that `output` is carried on through objects of type (so there's there's no data loss in the calls chain) `Eco::API::UseCases::BaseIO` (i.e. `io.new`)
|
68
|
+
- `#for`
|
69
|
+
- **now** it only requires a `block` if no `key` is provided
|
70
|
+
- `Eco::Data::Locations::NodeBase::TagValidations`
|
71
|
+
- made module re-usable, by removing dependency on `clean_id` method.
|
72
|
+
- Improved the **patch** on exception that adds method `#patch_full_message`
|
73
|
+
- Parameter `trace_count` added (`default: -1` for full trace)
|
74
|
+
|
75
|
+
### Fixed
|
76
|
+
- `Eco::Data::Locations::NodeBase::Treeify`
|
77
|
+
- **bug** on strings and interpolation when building the warning/error messages
|
78
|
+
- **added** detection and _warnings_ for **unlinked parents**: as `get_children` is called from the top via `nil` (those that are top level nodes), and all the call chain to collect children goes through their `parent_id` relationship.
|
79
|
+
- If the input nodes had some where there's no direct link between `nil` and a node `id` that is a `parent_id`, `parents[node.id]` would never be called. Meaning that in an input with a list of nodes, there could be clusters of subtrees that do not add/link to the top level (`nil`).
|
80
|
+
- It now gathers those separated subtrees in an `Array` parameter called `unlinked_trees`
|
81
|
+
- `Eco::API::Session::Config::Workflow`
|
82
|
+
- Returning an `Eco::API::UseCases::BaseIO` from callbacks `before`, `after` and `run` would raise an `ArgumentError`.
|
83
|
+
- **Now** the original `io` is returned otherwise the returned value is a `BaseIO`
|
84
|
+
- `Eco::API::Session::Config::Workflow`
|
85
|
+
- **changed** `open` to alias method for `with` (open was clashing)
|
86
|
+
- `Eco::API::UseCases::GraphQL::Helpers::Location::Base`
|
87
|
+
- **removed** `enviro` param for org tagtree built
|
88
|
+
- `Eco::API::UseCases::Cli::DSL`
|
89
|
+
- `::callback` was not acting like a DSL method, which would just return `nil` always (lost `block`)
|
90
|
+
- CLI arguments are unique. If a Cli class has already been run, no need to re-run it. Cli class re-usability is still not in the pipeline, and therefore, it must be run only once.
|
91
|
+
- `Eco::Data::Locations::NodePlain`
|
92
|
+
- `serializer` referred to an non existing constant.
|
93
|
+
- **IMPORTANT** `parent_id` should be `cleaned` as well. Otherwise parents with an id cleanage don't match their children's `parent_id`
|
94
|
+
- `Eco::API::Common::ClassHelpers`
|
95
|
+
- `::inerited` method must call `super` to be able to chain other calls
|
96
|
+
- `Eco::API::Common::Session::Mailer`
|
97
|
+
- The logging message was not printing who the email was sent to.
|
10
98
|
|
11
99
|
## [2.6.0] - 2024-02-03
|
12
100
|
|
13
101
|
### Added
|
102
|
+
- New use case to `-export-tree` (**tagtree extract**)
|
103
|
+
- `Eco::API::UseCases::Default::Locations::TagtreeExtract`
|
14
104
|
- `Eco::API::UseCases::UseCase`
|
15
105
|
- added `#classed_definition` to expose the original class definition
|
16
106
|
- injected further parameter as instance variables to the original class definition on run-time.
|
data/README.md
CHANGED
data/eco-helpers.gemspec
CHANGED
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
|
|
42
42
|
spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
|
43
43
|
spec.add_dependency 'amatch', '>= 0.4.1', '< 0.5'
|
44
44
|
spec.add_dependency 'jaro_winkler', '>= 1.5.6', '< 1.6'
|
45
|
-
spec.add_dependency 'nokogiri', '>= 1.13', '< 1.
|
45
|
+
spec.add_dependency 'nokogiri', '>= 1.13', '< 1.17'
|
46
46
|
spec.add_dependency 'roo', '>= 2.10.1', '< 2.11'
|
47
47
|
spec.add_dependency 'roo-xls', '>= 1.2.0', '< 1.3'
|
48
48
|
spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
|
@@ -129,13 +129,13 @@ module Eco
|
|
129
129
|
# - mutating methods would reflect the changes on other classes as well
|
130
130
|
# - therefore, `freeze` will be called on the values that are inherited.
|
131
131
|
def inherited(subclass)
|
132
|
+
super
|
132
133
|
inheritable_class_vars.each do |var|
|
133
134
|
instance_var = instance_variable_name(var)
|
134
135
|
value = instance_variable_get(instance_var)
|
135
136
|
subclass.instance_variable_set(instance_var, value.freeze)
|
136
137
|
end
|
137
138
|
end
|
138
|
-
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::Workflow
|
2
|
+
ORG = 'your organization'.freeze
|
3
|
+
TRACE_COUNT = 3
|
4
|
+
|
5
|
+
inheritable_class_vars :config_block
|
6
|
+
|
7
|
+
config_block do
|
8
|
+
puts "running from class #{self}"
|
9
|
+
exception do |err, io|
|
10
|
+
self.error = err
|
11
|
+
log(:debug) { err.patch_full_message }
|
12
|
+
workflow.run(:close, io: io)
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:close) do |_wf, io|
|
16
|
+
next if options.dig(:workflow, :no_email)
|
17
|
+
next unless session.mailer?
|
18
|
+
next if session.config.dry_run?
|
19
|
+
next unless session.config.run_mode_remote?
|
20
|
+
next unless some_update?(io) || error?
|
21
|
+
|
22
|
+
subject = base_subject
|
23
|
+
|
24
|
+
if session.job_groups.empty? && error?
|
25
|
+
subject = "#{subject} - Exception!"
|
26
|
+
session.mail(subject: subject, body: errors_n_warnings(io))
|
27
|
+
else
|
28
|
+
subject = "#{subject} & Errors" if session.job_groups.errors?
|
29
|
+
subject = "#{subject} - Exception!" if error?
|
30
|
+
|
31
|
+
msg = "#{session.summary}\n"
|
32
|
+
msg += errors_n_warnings(io)
|
33
|
+
|
34
|
+
session.mail(subject: subject, body: msg) unless msg.strip.empty?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class << self
|
40
|
+
attr_accessor :error
|
41
|
+
|
42
|
+
def org_name
|
43
|
+
self::ORG
|
44
|
+
end
|
45
|
+
|
46
|
+
def base_subject
|
47
|
+
"#{org_name} (#{active_enviro}) at #{Time.now.iso8601}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def some_update?(io)
|
51
|
+
cli.config.usecases.active(io: io).any? do |usecase, data|
|
52
|
+
[:transform, :sync].any? { |type| usecase.type == type }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def error?
|
57
|
+
!!error
|
58
|
+
end
|
59
|
+
|
60
|
+
def errors_n_warnings(io)
|
61
|
+
[error_message, log_err_n_warn(io)].join("\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
def log_err_n_warn(io)
|
65
|
+
warn_errors = io.logger.cache.logs(level: [:error, :warn])
|
66
|
+
return if warn_errors.empty?
|
67
|
+
"WARNINGS & ERRORS:\n#{warn_errors.join('')}\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
def error_message
|
71
|
+
error&.patch_full_message(trace_count: 3)
|
72
|
+
end
|
73
|
+
|
74
|
+
def trace_count
|
75
|
+
self::TRACE_COUNT
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Eco::API::Common::Loaders::Config
|
2
|
+
extend Eco::API::Common::ClassHelpers
|
3
|
+
extend Eco::Language::Methods::DelegateMissing
|
4
|
+
inheritable_class_vars :delegate_missing_to
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# To create samples of configurations
|
8
|
+
def config_block(&block)
|
9
|
+
return @config_block unless block_given?
|
10
|
+
@config_block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def config
|
14
|
+
ASSETS.config
|
15
|
+
end
|
16
|
+
|
17
|
+
def cli
|
18
|
+
ASSETS.cli
|
19
|
+
end
|
20
|
+
|
21
|
+
def active_enviro
|
22
|
+
config.active_enviro
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
delegate_missing_to :config
|
27
|
+
end
|
28
|
+
|
29
|
+
require_relative 'config/workflow'
|
@@ -3,7 +3,6 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module Loaders
|
5
5
|
class Policy < Eco::API::Common::Loaders::CaseBase
|
6
|
-
|
7
6
|
def initialize(policies)
|
8
7
|
raise "Expected Eco::API::Policies. Given #{policies.class}" unless policies.is_a?(Eco::API::Policies)
|
9
8
|
policies.define(self.name, &self.method(:main))
|
@@ -17,7 +16,6 @@ module Eco
|
|
17
16
|
def main(people, session, options, policy, job)
|
18
17
|
raise "You should implement this method"
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
@@ -33,7 +33,9 @@ module Eco
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
).tap do |response|
|
36
|
-
|
36
|
+
msg = "Sent email (MessageId: #{response.message_id}) to #{fetch_destination(to: to, cc: cc, bcc: bcc)}"
|
37
|
+
puts msg
|
38
|
+
logger.debug(msg)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class ::Exception
|
2
|
-
def patch_full_message
|
2
|
+
def patch_full_message(trace_count: -1)
|
3
3
|
begin
|
4
4
|
msg = []
|
5
5
|
tracing = backtrace ? backtrace : []
|
6
|
-
tracing = (self.class == SystemStackError) ? tracing[1..30] : tracing[1
|
6
|
+
tracing = (self.class == SystemStackError) ? tracing[1..30] : tracing[1..trace_count]
|
7
7
|
tracing ||= []
|
8
8
|
msg << "\n#{tracing.first} \n#{message} (#{self.class.to_s})"
|
9
9
|
tracing.each_with_index {|bt, i| msg << "#{" "*8}#{i+1}: from #{bt}"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Object
|
2
|
+
# From ruby3
|
3
|
+
# `NameError` prints the internals of the object as well as subobjects
|
4
|
+
# which is really unnecessary
|
5
|
+
# @example
|
6
|
+
# class Foo; attr_writer :bar; end
|
7
|
+
# foo = Foo.new
|
8
|
+
# foo2 = Foo.new
|
9
|
+
# foo.bar = foo2
|
10
|
+
# h = {a: 1, b: 2, c: foo}
|
11
|
+
# foo2.bar = h
|
12
|
+
# h.foo
|
13
|
+
# #=> undefined method `foo' for {:a=>1, :b=>2, :c=>#<Foo:0x000002343276b520 @bar=#<Foo:0x0000023437e91ca0 @bar={...}>>}:Hash (NoMethodError)
|
14
|
+
# What's the use of such a detail when it's just a missing method at the top of it?
|
15
|
+
def inspect
|
16
|
+
to_s
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'ruby3/object'
|
@@ -7,6 +7,9 @@ module Eco
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
if Gem::Version.create('3.0.0') <= Gem::Version.create(RUBY_VERSION)
|
11
|
+
require_relative 'version_patches/ruby3'
|
12
|
+
end
|
10
13
|
require_relative 'version_patches/object'
|
11
14
|
require_relative 'version_patches/exception'
|
12
15
|
require_relative 'version_patches/hash'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Helper class to create a custom `Config`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::Config::BatchPolicies < Eco::API::Custom::Config
|
4
|
+
# batch_policies do
|
5
|
+
# create.max = 5
|
6
|
+
# update.max = 20
|
7
|
+
# end
|
8
|
+
# end
|
9
|
+
class Eco::API::Custom::Config < Eco::API::Common::Loaders::Config
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Helper class to create a custom `Config`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::Workflow::Mailer < Eco::API::Custom::Mailer
|
4
|
+
# ORG = "Org Name"
|
5
|
+
# end
|
6
|
+
class Eco::API::Custom::Mailer < Eco::API::Common::Loaders::Workflow::Mailer
|
7
|
+
extend Eco::Language::Klass::WhenInherited
|
8
|
+
when_inherited(&config_block)
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Helper class to create a custom `Config`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::Config::DefaultOptions < Eco::API::Custom::Workflow
|
4
|
+
# after(:options) do
|
5
|
+
# options.deep_merge!(send_invites: false) unless options.dig(:send_invites)
|
6
|
+
# end
|
7
|
+
# end
|
8
|
+
class Eco::API::Custom::Workflow < Eco::API::Common::Loaders::Workflow
|
9
|
+
end
|
data/lib/eco/api/custom.rb
CHANGED
@@ -7,6 +7,9 @@ module Eco
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require_relative 'custom/namespace'
|
10
|
+
require_relative 'custom/config'
|
11
|
+
require_relative 'custom/workflow'
|
12
|
+
require_relative 'custom/mailer'
|
10
13
|
require_relative 'custom/use_case'
|
11
14
|
require_relative 'custom/policy'
|
12
15
|
require_relative 'custom/error_handler'
|
@@ -20,9 +20,10 @@ module Eco
|
|
20
20
|
# @attr_reader min [Integer] `min` **required** number of occurrences of the property
|
21
21
|
class BasePolicy
|
22
22
|
extend Eco::API::Common::ClassHierarchy
|
23
|
+
# adds evaluate method to enable block calls as DSL
|
24
|
+
include Eco::Language::Methods::DslAble
|
23
25
|
|
24
26
|
class << self
|
25
|
-
|
26
27
|
# If the class for `key` exists, it returns it. Otherwise it generates it.
|
27
28
|
# @note for this to work, `key` should be one of the submodels of the current class' `model`
|
28
29
|
# @return [Eco::API::Session::Batch::BasePolicy] or subclass thereof
|
@@ -52,16 +53,14 @@ module Eco
|
|
52
53
|
end
|
53
54
|
|
54
55
|
if block
|
55
|
-
|
56
|
+
policy.evaluate(policy, &block)
|
56
57
|
self
|
57
58
|
else
|
58
59
|
policy
|
59
60
|
end
|
60
61
|
end
|
61
|
-
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
65
64
|
end
|
66
65
|
|
67
66
|
include Enumerable
|
@@ -75,6 +74,16 @@ module Eco
|
|
75
74
|
@policies = {}
|
76
75
|
end
|
77
76
|
|
77
|
+
def max(value = :unused)
|
78
|
+
return @max if value == :unused
|
79
|
+
self.max = value
|
80
|
+
end
|
81
|
+
|
82
|
+
def min(value = :unused)
|
83
|
+
return @min if value == :unused
|
84
|
+
self.min = value
|
85
|
+
end
|
86
|
+
|
78
87
|
def attr(as_namespace: false)
|
79
88
|
return @attr if !as_namespace || root?
|
80
89
|
"#{@_parent.attr(as_namespace: true)}:#{@attr}"
|
@@ -222,7 +231,6 @@ module Eco
|
|
222
231
|
return model if model.is_a?(Hash)
|
223
232
|
model.to_h if model.respond_to?(:to_h)
|
224
233
|
end
|
225
|
-
|
226
234
|
end
|
227
235
|
end
|
228
236
|
end
|
@@ -9,6 +9,8 @@ module Eco
|
|
9
9
|
# @attr_reader status [Eco::API::Session::Batch::Status] if launched: the `status` of the `batch`
|
10
10
|
# @attr_reader feedback [Eco::API::Session::Batch::Feedback] helper class for feedback and end-user decision making
|
11
11
|
class Job < Eco::API::Common::Session::BaseSession
|
12
|
+
include Eco::Language::Methods::DslAble
|
13
|
+
|
12
14
|
@types = [:get, :create, :update, :delete]
|
13
15
|
@sets = [:core, :details, :account]
|
14
16
|
|
@@ -278,14 +280,15 @@ module Eco
|
|
278
280
|
def api_included(full_queue)
|
279
281
|
return full_queue if type == :create
|
280
282
|
return full_queue unless excluded_callback = session.config.people.api_excluded
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
else
|
287
|
-
full_queue.select {|entry| !excluded_callback.call(entry, session, options, self)}
|
283
|
+
|
284
|
+
inc_excluded = options.dig(:include, :excluded)
|
285
|
+
excluded_only = inc_excluded.is_a?(Hash) && excluded[:only]
|
286
|
+
is_excluded = Proc.new do |entry|
|
287
|
+
evaluate(entry, session, options, self, &excluded_callback)
|
288
288
|
end
|
289
|
+
return full_queue.select(&is_excluded) if excluded_only
|
290
|
+
return full_queue if inc_excluded
|
291
|
+
full_queue.reject(&is_excluded)
|
289
292
|
end
|
290
293
|
|
291
294
|
# Applies the changes introduced by api policies
|
@@ -93,9 +93,16 @@ module Eco
|
|
93
93
|
includeArchivedNodes: include_archived
|
94
94
|
}.merge(kargs)
|
95
95
|
|
96
|
+
start = Time.now
|
96
97
|
return nil unless tree = graphql.currentOrganization.locationStructure(**kargs, &block)
|
98
|
+
end_time = Time.now
|
99
|
+
secs = (end_time - start).round(3)
|
97
100
|
|
98
|
-
Eco::API::Organization::TagTree.new(tree.treeify, id: tree.id, name: tree.name)
|
101
|
+
Eco::API::Organization::TagTree.new(tree.treeify, id: tree.id, name: tree.name).tap do |eco_tree|
|
102
|
+
cnt = eco_tree.count
|
103
|
+
per_sec = (cnt.to_f / secs).round(2)
|
104
|
+
session_logger.info("Loaded #{cnt} location nodes in #{secs} seconds (#{per_sec} nodes/sec)")
|
105
|
+
end
|
99
106
|
end
|
100
107
|
|
101
108
|
# Retrieves all the location structures of the organisation
|
@@ -110,11 +117,18 @@ module Eco
|
|
110
117
|
includeArchivedNodes: include_archived
|
111
118
|
}.merge(kargs)
|
112
119
|
|
120
|
+
start = Time.now
|
113
121
|
next unless trees = graphql.currentOrganization.locationStructures(**kargs, &block)
|
122
|
+
end_time = Time.now
|
123
|
+
secs = (end_time - start).round(3)
|
124
|
+
cnt = 0
|
114
125
|
trees.each do |tree|
|
115
126
|
eco_tree = Eco::API::Organization::TagTree.new(tree.treeify, id: tree.id, name: tree.name)
|
127
|
+
cnt += eco_tree.count
|
116
128
|
eco_trees.push(eco_tree)
|
117
129
|
end
|
130
|
+
per_sec = (cnt.to_f / secs).round(2)
|
131
|
+
session_logger.info("Loaded #{cnt} location nodes in #{secs} seconds (#{per_sec} nodes/sec)")
|
118
132
|
end
|
119
133
|
end
|
120
134
|
|