eco-helpers 2.5.9 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/CHANGELOG.md +65 -4
  4. data/eco-helpers.gemspec +20 -16
  5. data/lib/eco/api/common/loaders/base.rb +2 -9
  6. data/lib/eco/api/common/loaders/use_case.rb +27 -1
  7. data/lib/eco/api/common/people/default_parsers.rb +2 -2
  8. data/lib/eco/api/common/people/person_entry.rb +3 -0
  9. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +111 -16
  10. data/lib/eco/api/common/session/base_session.rb +4 -0
  11. data/lib/eco/api/common/session/environment.rb +4 -0
  12. data/lib/eco/api/common/session/sftp.rb +1 -1
  13. data/lib/eco/api/organization/tag_tree.rb +20 -23
  14. data/lib/eco/api/session/batch/job.rb +4 -4
  15. data/lib/eco/api/session/batch/jobs.rb +2 -2
  16. data/lib/eco/api/session/batch/jobs_groups.rb +2 -2
  17. data/lib/eco/api/session/config/files.rb +2 -2
  18. data/lib/eco/api/session/config/people.rb +2 -2
  19. data/lib/eco/api/session/config/sftp.rb +4 -0
  20. data/lib/eco/api/session/config/tagtree.rb +9 -8
  21. data/lib/eco/api/session/config/workflow.rb +3 -2
  22. data/lib/eco/api/session/config.rb +7 -0
  23. data/lib/eco/api/session.rb +17 -2
  24. data/lib/eco/api/usecases/cli/dsl.rb +84 -0
  25. data/lib/eco/api/usecases/cli/option.rb +19 -0
  26. data/lib/eco/api/usecases/cli.rb +13 -0
  27. data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +24 -0
  28. data/lib/eco/api/usecases/{default_cases → default/locations}/codes_to_tags_case.rb +1 -1
  29. data/lib/eco/api/usecases/{default_cases → default/locations}/create_tag_paths_case.rb +2 -2
  30. data/lib/eco/api/usecases/{default_cases → default/locations}/csv_to_tree_case.rb +1 -1
  31. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +173 -0
  32. data/lib/eco/api/usecases/default/locations.rb +15 -0
  33. data/lib/eco/api/usecases/{default_cases → default/people}/analyse_people_case.rb +1 -1
  34. data/lib/eco/api/usecases/{default_cases → default/people}/change_email_case.rb +1 -1
  35. data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +66 -0
  36. data/lib/eco/api/usecases/{default_cases → default/people}/clear_abilities_case.rb +1 -1
  37. data/lib/eco/api/usecases/{default_cases → default/people}/org_data_convert_case.rb +1 -1
  38. data/lib/eco/api/usecases/{default_cases → default/people}/refresh_case.rb +1 -1
  39. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_sync_case.rb +2 -2
  40. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_trans_case.rb +1 -1
  41. data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +5 -0
  42. data/lib/eco/api/usecases/{default_cases → default/people}/restore_db_case.rb +1 -1
  43. data/lib/eco/api/usecases/{default_cases → default/people}/set_default_tag_case.rb +1 -1
  44. data/lib/eco/api/usecases/{default_cases → default/people}/supers_cyclic_identify_case.rb +1 -1
  45. data/lib/eco/api/usecases/{default_cases → default/people}/supers_hierarchy_case.rb +1 -1
  46. data/lib/eco/api/usecases/{default_cases → default/people}/switch_supervisor_case.rb +1 -1
  47. data/lib/eco/api/usecases/{default_cases → default/people}/transfer_account_case.rb +1 -1
  48. data/lib/eco/api/usecases/default/people.rb +25 -0
  49. data/lib/eco/api/usecases/default.rb +16 -0
  50. data/lib/eco/api/usecases/default_cases/samples/cli/sftp_cli.rb +46 -0
  51. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +21 -9
  52. data/lib/eco/api/usecases/default_cases.rb +2 -30
  53. data/lib/eco/api/usecases/graphql/utils/sftp.rb +1 -1
  54. data/lib/eco/api/usecases/use_case.rb +21 -7
  55. data/lib/eco/api/usecases/use_case_chain.rb +2 -2
  56. data/lib/eco/api/usecases.rb +4 -1
  57. data/lib/eco/assets.rb +1 -3
  58. data/lib/eco/cli/config/filters/people_filters.rb +0 -1
  59. data/lib/eco/cli/config/filters.rb +2 -6
  60. data/lib/eco/cli/config/help.rb +0 -1
  61. data/lib/eco/cli/config/input.rb +0 -1
  62. data/lib/eco/cli/config/options_set.rb +3 -4
  63. data/lib/eco/cli/config/use_cases.rb +13 -6
  64. data/lib/eco/cli/config.rb +4 -5
  65. data/lib/eco/cli/scripting/args_helpers.rb +1 -1
  66. data/lib/eco/cli/scripting/argument.rb +0 -1
  67. data/lib/eco/cli/scripting/arguments.rb +0 -2
  68. data/lib/eco/cli.rb +0 -1
  69. data/lib/eco/{cli/config/default → cli_default}/input_filters.rb +0 -1
  70. data/lib/eco/{cli/config/default → cli_default}/people_filters.rb +0 -1
  71. data/lib/eco/{cli/config/default → cli_default}/usecases.rb +2 -52
  72. data/lib/eco/{cli/config/default → cli_default}/workflow.rb +3 -2
  73. data/lib/eco/cli_default.rb +13 -0
  74. data/lib/eco/csv/table.rb +0 -1
  75. data/lib/eco/data/files/encoding.rb +1 -1
  76. data/lib/eco/data/files/helpers.rb +1 -1
  77. data/lib/eco/data/locations/convert.rb +8 -4
  78. data/lib/eco/data/locations/node_base/csv_convert.rb +4 -4
  79. data/lib/eco/data/mapper.rb +6 -1
  80. data/lib/eco/version.rb +1 -1
  81. metadata +156 -79
  82. data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +0 -160
  83. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +0 -14
  84. data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +0 -74
  85. data/lib/eco/api/usecases/default_cases/create_details_case.rb +0 -20
  86. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +0 -21
  87. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +0 -12
  88. data/lib/eco/api/usecases/default_cases/new_email_case.rb +0 -13
  89. data/lib/eco/api/usecases/default_cases/new_id_case.rb +0 -12
  90. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +0 -10
  91. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +0 -16
  92. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +0 -18
  93. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +0 -16
  94. data/lib/eco/api/usecases/default_cases/tagtree_case.rb +0 -42
  95. data/lib/eco/api/usecases/default_cases/update_details_case.rb +0 -15
  96. data/lib/eco/cli/config/default.rb +0 -16
  97. /data/lib/eco/{cli/config/default → cli_default}/input.rb +0 -0
  98. /data/lib/eco/{cli/config/default → cli_default}/options.rb +0 -0
  99. /data/lib/eco/{cli/config/default → cli_default}/people.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f78310ad18a148ef707c1735932215754c047041fd3a1539a1434a9d213427d
4
- data.tar.gz: 8d795944674e2cb2148a796ca1c1aa0817f342c5ffb9228ef22a99fe3cc39179
3
+ metadata.gz: 796d1fc03564d9e1bd9389954b164c7d8e1469793871191390824a6e32fabc67
4
+ data.tar.gz: 7d820fb01377374aca6059f8df28f9bb596c1fa023f7ebbfdc4f94d011e703a7
5
5
  SHA512:
6
- metadata.gz: 88cbb36569c4683decb9210d9db4ed2da2e205c8d06f170707b15cb9085fa111d39407eefd495211022129c4532172fd69bebe266123ab9a10c4663f2c83a940
7
- data.tar.gz: 49795a3e5c994e1d0a74f46257865062501ed0b400fba66a9de1e81c6b3826a3a7f71ebd2e46df48a0d13577cafc677d23e7b60ff9768a42229f18bec4cce703
6
+ metadata.gz: c89c374aa377818d82d85eba913ffb9392343276373fbca166b53471dc2c70cdd3caa29c7050b7f2547ff3191d5078848238b11a6fe3264171ffc968bb38afb1
7
+ data.tar.gz: 98f7acfa91c4dd78b2c63340b620a2be5d7407bd074a23ea6908594ac79e126e6e3b1b837e5391acbd64dda59978ca380089f9b8d0b513563ca0c345b1d2b59a
data/.gitignore CHANGED
@@ -3,7 +3,7 @@ Gemfile.lock
3
3
 
4
4
  # build artifacts
5
5
  *.gem
6
- /.bundle/
6
+ /.bundle
7
7
  /vendor/bundle
8
8
  /spec/reports/
9
9
  /tmp/
@@ -18,4 +18,4 @@ Gemfile.lock
18
18
  # rspec failure tracking
19
19
  .rspec_status
20
20
  scratch.rb
21
- .byebug_history
21
+ .byebug_history
data/CHANGELOG.md CHANGED
@@ -1,13 +1,74 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.5.10] - 2023-09-xx
4
+ ## [2.6.1] - 2024-02-xx
5
+
6
+ ### Added
7
+ ### Changed
8
+ ### Fixed
9
+
10
+
11
+ ## [2.6.0] - 2024-02-03
12
+
13
+ ### Added
14
+ - `Eco::API::UseCases::UseCase`
15
+ - added `#classed_definition` to expose the original class definition
16
+ - injected further parameter as instance variables to the original class definition on run-time.
17
+ - Expose `live_trees` retrieval:
18
+ - `Eco::API::Session#live_trees`
19
+ - `Eco::API::Session::Config#live_trees`
20
+ - Ability to CLI-integrate use cases and their options via class
21
+ - `Eco::API::UseCases::Cli`
22
+ - Added use case to extract live locations structure (`-export-tree`)
23
+ - `Eco::API::UseCases::GraphQL::Cases::TagtreeExtract`
24
+ - `#api?` method to check if an API version is available
25
+ - `Eco::API::Common::Session::Environment#api?`
26
+ - `Eco::API::Common::Session::BaseSession#api?`
27
+ - `Eco::API::Organization::TagTree#merge` the merge method for tagtrees
28
+ - It allows to have all structure nodes available to check if a tag belongs to them
29
+ - `Eco::API::Session::Config::Workflow`
30
+ - **added** `open` alias method for `for`
31
+ - `Eco::Data::Mapper#self_mapped?` to check if a value maps to itself
32
+
33
+ ### Changed
34
+ - upgrade `ecoportal-api-graphql`, `ecoportal-api-v2` and `ecoportal-api`
35
+ - `Eco::API::Session#tagtree`: added parameters to be able to obtain:
36
+ - `:live` live trees if graphql api is available on the enviro
37
+ - `:merge` to merge all live trees if there isn't just one
38
+ - Tagtree retrieval: remove `enviro` param where there's no caching
39
+ - Removed also from `Eco::API::Organization::TagTree::new`
40
+ - Removed some use cases:
41
+ - `Eco::API::UseCases::DefaultCases::AbstractPolicyGroupAbilities`
42
+ - `Eco::API::UseCases::DefaultCases::AppendUsergroupsCase`
43
+ - `Eco::API::UseCases::DefaultCases::CreateDetailsCase`
44
+ - `Eco::API::UseCases::DefaultCases::CreateDetailsWithSupervisorCase`
45
+ - `Eco::API::UseCases::DefaultCases::EmailAsIdCase`
46
+ - `Eco::API::UseCases::DefaultCases::NewIdCase`
47
+ - `Eco::API::UseCases::DefaultCases::RemoveAccountSyncCase`
48
+ - `Eco::API::UseCases::DefaultCases::RemoveAccountTransCase`
49
+ - `Eco::API::UseCases::DefaultCases::NewEmailCase`
50
+ - `Eco::API::UseCases::DefaultCases::SetSupervisorCase`
51
+ - `Eco::API::UseCases::DefaultCases::TagTree`
52
+ - `Eco::API::UseCases::DefaultCases::UpdateDetailsCase`
53
+ - `Eco::API::UseCases::DefaultCases::ResetLandingPageCase`
54
+ - Moved some default use cases to new namespace `Eco::API::UseCases::Default`
55
+
56
+ ### Fixed
57
+ - Compatibility with `ruby 3`
58
+ - replaced `Proc.new` (with no block) by `block` in methods
59
+ - replaced `File#exists?` by `File#exist?`
60
+ - call to method's `super` not specifying args, no longer passes keyed/named args via simple splat `*` (but only double splat `**`)
61
+ - limit `nokogiri` gem to prev `1.16` (as it requires ruby 3 from thereon)
62
+ - `Eco::API::Common::People::PersonEntryAttributeMapper`
63
+ - `#aliased_attrs` was missing internal attrs that have been mapped directly as external attrs (same ext attr name as int attr name)
64
+
65
+ ## [2.5.10] - 2023-11-22
5
66
 
6
- ### Added
7
- ### Changed
8
67
  ### Fixed
68
+ - `Eco::API::UseCases::DefaultCases::ReinviteSyncCase` remove unnecessary additional parameters on call.
69
+ - `Eco::API::Session::Config::SFTP#enviro_subpaths` provided that a current workaround can be skipped
9
70
 
10
- ## [2.5.9] - 2023-09-01
71
+ ## [2.5.9] - 2023-09-05
11
72
 
12
73
  The input **csv** of trees could come very compacted, which had unintended consequences.
13
74
  - This is a fix to this scenario.
data/eco-helpers.gemspec CHANGED
@@ -24,24 +24,28 @@ Gem::Specification.new do |spec|
24
24
  #spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_development_dependency "bundler", ">= 2.4.8", "< 3"
28
- spec.add_development_dependency "rspec", ">= 3.10.0", "< 4"
27
+ spec.add_development_dependency "bundler", ">= 2.4.12", "< 3"
28
+ spec.add_development_dependency "rspec", ">= 3.12.0", "< 4"
29
29
  spec.add_development_dependency "rake", ">= 13.0.3", "< 14"
30
- spec.add_development_dependency "yard", ">= 0.9.26", "< 1"
31
- spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 4"
30
+ spec.add_development_dependency "yard", ">= 0.9.34", "< 1"
31
+ spec.add_development_dependency "redcarpet", ">= 3.6.0", "< 4"
32
32
 
33
- spec.add_dependency 'ecoportal-api', '>= 0.9.5', '< 0.10'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 1.1.3', '< 1.2'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.10', '< 0.4'
36
- spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
37
- spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
38
- spec.add_dependency 'dotenv', '>= 2.7.6', '< 3'
39
- spec.add_dependency 'net-sftp', '>= 3.0.0', '< 4'
40
- spec.add_dependency 'hashdiff', '>= 1.0.1', '< 1.1'
33
+ spec.add_dependency 'ecoportal-api', '>= 0.9.6', '< 0.10'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 1.1.5', '< 1.2'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.13', '< 0.4'
36
+ spec.add_dependency 'aws-sdk-s3', '>= 1.142.0', '< 2'
37
+ spec.add_dependency 'aws-sdk-ses', '>= 1.58.0', '< 2'
38
+ spec.add_dependency 'dotenv', '>= 2.8.1', '< 3'
39
+ spec.add_dependency 'net-ssh', '>= 7.2.1', '< 8'
40
+ spec.add_dependency 'net-sftp', '>= 4.0.0', '< 5'
41
+ spec.add_dependency 'hashdiff', '>= 1.1.0', '< 1.2'
41
42
  spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
42
- spec.add_dependency 'amatch', '>= 0.4.0', '< 0.5'
43
- spec.add_dependency 'jaro_winkler', '>= 1.5.4', '< 1.6'
44
- spec.add_dependency 'roo', '>= 2.8.3', '< 2.9'
43
+ spec.add_dependency 'amatch', '>= 0.4.1', '< 0.5'
44
+ spec.add_dependency 'jaro_winkler', '>= 1.5.6', '< 1.6'
45
+ spec.add_dependency 'nokogiri', '>= 1.13', '< 1.16'
46
+ spec.add_dependency 'roo', '>= 2.10.1', '< 2.11'
45
47
  spec.add_dependency 'roo-xls', '>= 1.2.0', '< 1.3'
46
- spec.add_dependency 'docx', '>= 0.6.2', '< 0.7'
48
+ spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
49
+ spec.add_dependency 'docx', '>= 0.8.0', '< 0.9'
50
+ spec.add_dependency 'rubyzip', '>= 2.3.2', '< 2.4'
47
51
  end
@@ -30,10 +30,6 @@ module Eco
30
30
  raise "You should implement this method"
31
31
  end
32
32
 
33
- def name
34
- self.class.name
35
- end
36
-
37
33
  private
38
34
 
39
35
  def session
@@ -54,11 +50,8 @@ module Eco
54
50
 
55
51
  def abort(msg, raising: true)
56
52
  logger.error(msg)
57
- if raising
58
- raise msg
59
- else
60
- exit(1)
61
- end
53
+ raise msg if raising
54
+ exit 1
62
55
  end
63
56
  end
64
57
  end
@@ -11,9 +11,31 @@ module Eco
11
11
  end
12
12
  @type = value
13
13
  end
14
+
15
+ def cli!
16
+ cli&.apply!
17
+ end
18
+
19
+ def cli(cli_class = nil)
20
+ if cli_class.is_a?(Class)
21
+ raise ArgumentError, "cli_class should inherit from Eco::API::UseCases::Cli" unless cli_class < Eco::API::UseCases::Cli
22
+ @cli = cli_class
23
+ elsif cli_class.nil?
24
+ return @cli if instance_variable_defined?(:@cli) && !@cli.nil?
25
+ # try to see if it's namespaced after the use case it provisions cli integration
26
+ begin
27
+ try_class = [self.to_s, 'Cli'].join('::')
28
+ @cli = Kernel.const_get(try_class)
29
+ rescue NameError
30
+ nil
31
+ end
32
+ else
33
+ raise ArgumentError, "Expecting a class. Given: #{cli_class.class} object"
34
+ end
35
+ end
14
36
  end
15
37
 
16
- inheritable_class_vars :type
38
+ inheritable_class_vars :type, :cli
17
39
 
18
40
  def initialize(usecases)
19
41
  raise "Expected Eco::API::UseCases. Given #{usecases.class}" unless usecases.is_a?(Eco::API::UseCases)
@@ -33,6 +55,10 @@ module Eco
33
55
  def type
34
56
  self.class.type
35
57
  end
58
+
59
+ def cli_apply!
60
+ self.class.cli!
61
+ end
36
62
  end
37
63
  end
38
64
  end
@@ -8,8 +8,8 @@ module Eco
8
8
  autoloads_children_of "Eco::API::Common::Loaders::Parser"
9
9
  autoload_namespace "Eco::API::Common::People::DefaultParsers"
10
10
 
11
- def initialize(*args)
12
- super(*args)
11
+ def initialize(**kargs)
12
+ super(**kargs)
13
13
  define_defaults
14
14
  end
15
15
 
@@ -3,6 +3,7 @@ module Eco
3
3
  module Common
4
4
  module People
5
5
  class PersonEntry
6
+ DEBUG = false
6
7
 
7
8
  # This class is meant to provide a common interface to access entries of source data that come in different formats.
8
9
  # @note
@@ -37,6 +38,8 @@ module Eco
37
38
  @mapped_entry = __mapped_entry(@internal_entry)
38
39
  @external_entry = __external_entry(@mapped_entry)
39
40
  end
41
+
42
+ (print_models; exit(1)) if DEBUG
40
43
  end
41
44
 
42
45
  # Generates a new entry
@@ -4,6 +4,7 @@ module Eco
4
4
  module People
5
5
  # @attr_reader direct_attrs [Array<String>] only those internal attributes present in the person entry that do **not** have an internal/external name mapping.
6
6
  class PersonEntryAttributeMapper
7
+ DEBUG = false
7
8
  @@cached_warnings = {}
8
9
 
9
10
  attr_reader :aliased_attrs, :direct_attrs
@@ -182,22 +183,59 @@ module Eco
182
183
 
183
184
  private
184
185
 
186
+ # Whether the maps include this `attr` as mapped to itself
187
+ def self_mapped_attr?(attr)
188
+ return false if !@attr_map
189
+ @attr_map.self_mapped?(attr)
190
+ end
191
+
192
+ # Whether the maps include this `attr` as mapped from to some other or itself
193
+ def external_attr?(attr)
194
+ return false if !@attr_map
195
+ @attr_map.external?(attr)
196
+ end
197
+
185
198
  # when parsing:
186
199
  def init_attr_trackers
187
200
  # (def) all internal attributes we can expect
188
201
  def_all_attrs = @person_parser.all_model_attrs
189
202
  # (def) internal attrs with no aliasing nor parser definition (expected to be direct)
190
203
  def_unlinked = @person_parser.undefined_model_attrs.select { |attr| !to_external(attr) }
191
- # (def) those with parser or alias:
192
- def_linked = def_all_attrs - def_unlinked
204
+
205
+ debug(
206
+ def_unlinked,
207
+ "(def_unlinked) expected to be direct (not parser defined nor aliased)"
208
+ )
209
+
193
210
  # (data) data attributes (actual attributes of the entry)
194
211
  data_attrs = attributes(@external_entry)
212
+ # (data) attributes of the data that COULD come directly as internal attribute names
213
+ # => WARNING: this includes ext direct attrs that may be aliased to other int attrs
214
+ data_direct_attrs_raw = data_attrs & def_all_attrs
215
+ # (data) direct (int) ext data attrs mapped
216
+ data_direct_mapped = data_direct_attrs_raw.select { |attr| external_attr?(attr) }
217
+ # (data) direct (int) ext data attrs mapped to themselves
218
+ data_direct_self_mapped = data_direct_attrs_raw.select { |attr| self_mapped_attr?(attr) }
219
+ # (data) direct (int) ext data attrs mapped only to another attr
220
+ data_direct_renamed = data_direct_mapped - data_direct_self_mapped
195
221
  # (data) attributes of the data that come directly as internal attribute names
196
- data_direct_attrs = data_attrs & def_all_attrs
222
+ data_direct_attrs = data_direct_attrs_raw - data_direct_renamed
223
+
224
+ debug(
225
+ data_direct_attrs,
226
+ "(data_direct_attrs) attributes of the data that come directly as internal attribute names (data_direct_attrs_raw - data_direct_renamed)"
227
+ )
228
+
229
+ # (def) configured as alised (int <-> ext attrs) + accept/include int attrs as ext attrs
230
+ def_int_aliased_raw = def_all_attrs.select { |attr| to_external(attr) }
231
+ # (def) aliasable int attrs of the input data (excludes int attrs direct as ext attrs that got renamed)
232
+ def_int_aliased = def_int_aliased_raw - data_direct_renamed
233
+ # (def) ext attrs of the data's aliasable int attrs (def_int_aliased)
234
+ def_ext_alias = def_int_aliased.map { |attr| to_external(attr) }
235
+ # (def) those ext attrs that map to multiple int attrs
236
+ def_ext_multi_alias = def_ext_alias.detect { |attr| def_ext_alias.count(attr) > 1 }
237
+ # (def) those ext attrs that are direct, mapt to themselves and some other
197
238
 
198
- # (def) configured as alised (internal <-> external attributes)
199
- def_int_aliased = def_all_attrs.select { |attr| to_external(attr) }
200
- def_ext_alias = def_int_aliased.map { |attr| to_external(attr) }
201
239
 
202
240
  # (data) virtual attrs (external alias of non native internal attr in data):
203
241
  data_vi_ext_alias = data_attrs.select do |attr|
@@ -210,27 +248,78 @@ module Eco
210
248
  @attr_map.to_internal(attr)
211
249
  end.compact
212
250
 
213
- # (data) attrs that could come aliased in the current data
251
+ # (data) int attrs that come aliased in the current data
214
252
  # => modify aliased based on those that came directly as internal attrs in the entry
215
- data_def_int_aliased = def_int_aliased - data_direct_attrs
253
+ data_def_int_aliased = (def_int_aliased - data_direct_attrs) | data_direct_self_mapped
216
254
  data_def_ext_alias = data_def_int_aliased.map { |attr| to_external(attr) }
217
- # (data) actual attrs of the data that come aliased
255
+ # (data) ext attrs of the data that come aliased
218
256
  data_ext_alias = data_def_ext_alias & data_attrs
257
+ # (data) all internal attributes that come aliased, with given the entry
258
+ aliased_attrs = data_def_int_aliased | data_vi_int_aliased
259
+
260
+ # render in the order that defines the model
261
+ @aliased_attrs = (def_all_attrs & aliased_attrs) | (aliased_attrs - def_all_attrs)
262
+
263
+ debug(
264
+ data_vi_int_aliased,
265
+ "(data_vi_int_aliased) virtual internal attrs (internal names of those virtual attrs)"
266
+ )
267
+
268
+ debug(
269
+ def_int_aliased,
270
+ "(def_int_aliased) aliasable int attrs of the input data (excludes int attrs direct as ext attrs that got renamed)"
271
+ )
272
+
273
+ debug(
274
+ def_ext_alias,
275
+ "(def_ext_alias) ext attrs of the data's aliasable int attrs (def_int_aliased)"
276
+ )
277
+
278
+ debug(
279
+ data_def_int_aliased,
280
+ "(data_def_int_aliased) int attrs that come aliased in the current data ((def_int_aliased - data_direct_attrs) | data_direct_self_mapped)"
281
+ )
282
+
283
+ debug(
284
+ data_ext_alias,
285
+ "(data_ext_alias) ext attrs of the data that come aliased (data_def_ext_alias & data_attrs)"
286
+ )
287
+
288
+ debug(
289
+ aliased_attrs,
290
+ "(aliased_attrs) all internal attributes that come aliased, with given the entry (data_def_int_aliased | data_vi_int_aliased)"
291
+ )
219
292
 
220
- # (data) all internal attributes that could come aliased, with given the entry
221
- @aliased_attrs = data_def_int_aliased + data_vi_int_aliased
222
293
  # (data) all those ext attrs present that will require aliasing
223
294
  #data_ext_alias_all = data_def_ext_alias + data_vi_ext_alias
224
- data_ext_alias_all = data_ext_alias + data_vi_ext_alias
295
+ data_ext_alias_all = data_ext_alias | data_vi_ext_alias
296
+
297
+ debug(
298
+ data_ext_alias_all,
299
+ "(data_ext_alias_all) all those ext attrs present that will require aliasing (data_ext_alias | data_vi_ext_alias)"
300
+ )
225
301
 
226
302
  # those that are direct external to internal:
227
303
  data_ext_direct = data_attrs - data_ext_alias_all
228
-
229
304
  # (data) attributes that do not require aliasing
230
305
  # to avoid collisions between internal names:
231
- #@direct_attrs = data_ext_direct - def_linked
232
- @direct_attrs = data_ext_direct
233
- @internal_attrs = @aliased_attrs | @direct_attrs
306
+ direct_attrs = data_ext_direct
307
+ # render in the order that defines the model
308
+ @direct_attrs = (def_all_attrs & direct_attrs) | (direct_attrs - def_all_attrs)
309
+
310
+ # (data) attributes that are being aliased
311
+ internal_attrs = @aliased_attrs | @direct_attrs
312
+ # render in the order that defines the model
313
+ @internal_attrs = (def_all_attrs & internal_attrs) | (internal_attrs - def_all_attrs)
314
+
315
+ debug(
316
+ @direct_attrs,
317
+ "(@direct_attrs) attributes that do not require aliasing (data_attrs - data_ext_alias_all)"
318
+ )
319
+ debug(
320
+ @internal_attrs,
321
+ "(@internal_attrs) aliased_attrs | @direct_attrs"
322
+ )
234
323
  end
235
324
 
236
325
  def attributes(value)
@@ -265,6 +354,12 @@ module Eco
265
354
  logger.fatal(msg)
266
355
  raise msg
267
356
  end
357
+
358
+ def debug(var, msg)
359
+ return unless DEBUG
360
+ puts "\n • #{msg}:"
361
+ pp var
362
+ end
268
363
  end
269
364
  end
270
365
  end
@@ -35,6 +35,10 @@ module Eco
35
35
  enviro.api(version: version)
36
36
  end
37
37
 
38
+ def api?(version: nil)
39
+ enviro.api?(version: version)
40
+ end
41
+
38
42
  def file_manager
39
43
  enviro.file_manager
40
44
  end
@@ -53,6 +53,10 @@ module Eco
53
53
  def api(version: nil)
54
54
  config.api(logger, version: version)
55
55
  end
56
+
57
+ def api?(version:)
58
+ config.apis.active_api.version_available?(version)
59
+ end
56
60
  end
57
61
  end
58
62
  end
@@ -24,7 +24,7 @@ module Eco
24
24
  rescue Exception => e
25
25
  msg = "Could not open SFTP session. Possible misconfiguration: #{e}"
26
26
  logger.error(msg)
27
- raise msg
27
+ raise
28
28
  end
29
29
  @sftp_session
30
30
  end
@@ -19,7 +19,6 @@ module Eco
19
19
  attr_reader :parent
20
20
  attr_reader :nodes, :children_count
21
21
  attr_reader :depth, :path
22
- attr_reader :enviro
23
22
 
24
23
  attr_reader :source
25
24
 
@@ -35,7 +34,7 @@ module Eco
35
34
  # ]}]
36
35
  # tree = TagTree.new(tree.to_json)
37
36
  # @param tagtree [String] representation of the tagtree in json.
38
- def initialize(tagtree = [], name: nil, id: nil, depth: -1, path: [], parent: nil, _weight: nil, enviro: nil)
37
+ def initialize(tagtree = [], name: nil, id: nil, depth: -1, path: [], parent: nil, _weight: nil)
39
38
  @depth = depth
40
39
  @parent = parent
41
40
 
@@ -45,9 +44,7 @@ module Eco
45
44
  else
46
45
  @source = tagtree
47
46
  end
48
- fatal("You are trying to initialize a TagTree with a null tagtree") if !@source
49
- fatal("Expecting Environment object. Given: #{enviro}") if enviro && !enviro.is_a?(API::Common::Session::Environment)
50
- @enviro = enviro
47
+ raise ArgumentError, "You are trying to initialize a TagTree with a null tagtree" if !@source
51
48
 
52
49
  if @source.is_a?(Array)
53
50
  @id = id
@@ -66,7 +63,7 @@ module Eco
66
63
  @path.push(@id) unless top?
67
64
 
68
65
  @nodes = @raw_nodes.map.with_index do |cnode, idx|
69
- TagTree.new(cnode, depth: depth + 1, path: @path.dup, parent: self, _weight: idx, enviro: @enviro)
66
+ self.class.new(cnode, depth: depth + 1, path: @path.dup, parent: self, _weight: idx)
70
67
  end
71
68
 
72
69
  init_hashes
@@ -80,11 +77,28 @@ module Eco
80
77
  !archived?
81
78
  end
82
79
 
80
+ # @note that archived nodes will also be passed over to the copy
83
81
  # @return [Eco::API::Organization::TagTree]
84
82
  def dup
85
83
  self.class.new(as_json, name: name, id: id)
86
84
  end
87
85
 
86
+ # @return [Array] with the differences
87
+ def diff(tagtree, differences: {}, level: 0, **options)
88
+ require 'hashdiff'
89
+ Hashdiff.diff(self.as_json, tagtree.as_json, **options.slice(:array_path, :similarity, :use_lcs))
90
+ end
91
+
92
+ # It generates a merged tagtree out of two sources
93
+ # @note it merges the first level nodes (and their children) as it comes
94
+ # @return [Eco::API::Organization::TagTree] result of merging both trees
95
+ def merge(other)
96
+ raise ArgumentError, "Expecting Eco::API::Organization::TagTree. Given: #{other.class}" unless other.is_a?(Eco::API::Organization::TagTree)
97
+ mid = [self.id, other.id].join('|')
98
+ mname = [self.name, other.name].join('|')
99
+ self.class.new(as_json | other.as_json, id: mid, name: mname)
100
+ end
101
+
88
102
  # @return [Eco::API::Organization::TagTree] with **non** `archived` nodes only
89
103
  def active_tree
90
104
  self.class.new(as_json(include_archived: false), name: name, id: id)
@@ -162,12 +176,6 @@ module Eco
162
176
  parent.name unless parent.top?
163
177
  end
164
178
 
165
- # @return [Array] with the differences
166
- def diff(tagtree, differences: {}, level: 0, **options)
167
- require 'hashdiff'
168
- Hashdiff.diff(self.as_json, tagtree.as_json, **options.slice(:array_path, :similarity, :use_lcs))
169
- end
170
-
171
179
  def top?
172
180
  depth == -1
173
181
  end
@@ -410,17 +418,6 @@ module Eco
410
418
  h.merge(n.hash_paths)
411
419
  end
412
420
  end
413
-
414
- def fatal(msg)
415
- raise msg if !@enviro
416
- @enviro.logger.fatal(msg)
417
- raise msg
418
- end
419
-
420
- def warn(msg)
421
- raise msg if !@enviro
422
- @enviro.logger.warn(msg)
423
- end
424
421
  end
425
422
  end
426
423
  end
@@ -105,7 +105,7 @@ module Eco
105
105
  unless unique && @queue_hash.key?(entry)
106
106
  @queue_hash[entry] = true
107
107
  @queue.push(entry)
108
- @callbacks[entry] = Proc.new if block_given?
108
+ @callbacks[entry] = block if block_given?
109
109
  end
110
110
  end
111
111
  end
@@ -230,13 +230,13 @@ module Eco
230
230
  end.join("\n")
231
231
  end
232
232
 
233
- def as_update(data, *args)
233
+ def as_update(data, **kargs)
234
234
  if data.is_a?(Array)
235
235
  data.map do |e|
236
- feedback.as_update(e, *args)
236
+ feedback.as_update(e, **kargs)
237
237
  end.compact.select {|e| e && !e.empty?}
238
238
  else
239
- feedback.as_update(data, *args)
239
+ feedback.as_update(data, **kargs)
240
240
  end
241
241
  end
242
242
 
@@ -74,10 +74,10 @@ module Eco
74
74
  # @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server.
75
75
  # @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch.
76
76
  # @return [Eco::API::Session::Batch::Job]
77
- def add(job)
77
+ def add(job, &block)
78
78
  fatal "Expected Eco::API::Session::Batch::Job object. Given #{job.class}" unless job.is_a?(Eco::API::Session::Batch::Job)
79
79
  @jobs[job.name] = job
80
- @callbacks[job] = Proc.new if block_given?
80
+ @callbacks[job] = block if block_given?
81
81
  end
82
82
 
83
83
  def pending?
@@ -63,7 +63,7 @@ module Eco
63
63
  # @yieldparam group [Eco::API::Session::Batch::Jobs] the group of jobs we have launched against the server.
64
64
  # @yieldparam group_status [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>] the status of the launched batch jobs.
65
65
  # @return [Eco::API::Session::Batch::Jobs] the group of jobs.
66
- def new(name, order: :last)
66
+ def new(name, order: :last, &block)
67
67
  fatal "Can't create job group named '#{name}' because it already exists." if exists?(name)
68
68
 
69
69
  Batch::Jobs.new(enviro, name: name).tap do |group|
@@ -75,7 +75,7 @@ module Eco
75
75
  @order.unshift(group)
76
76
  end
77
77
 
78
- @callbacks[group] = Proc.new if block_given?
78
+ @callbacks[group] = block if block_given?
79
79
  end
80
80
  end
81
81
 
@@ -26,9 +26,9 @@ module Eco
26
26
 
27
27
  attr_key :timestamp_pattern
28
28
 
29
- def add_validation(format)
29
+ def add_validation(format, &block)
30
30
  raise "Block must be given" unless block_given?
31
- @validations[format] = Proc.new
31
+ @validations[format] = block
32
32
  end
33
33
 
34
34
  def validate(format, input)
@@ -48,9 +48,9 @@ module Eco
48
48
  end
49
49
 
50
50
  # with given a person what is the criteria of exclusion
51
- def api_excluded
51
+ def api_excluded(&block)
52
52
  return self["api_excluded"] unless block_given?
53
- self["api_excluded"] = Proc.new
53
+ self["api_excluded"] = block
54
54
  end
55
55
 
56
56
  # internal-external fields map
@@ -12,6 +12,10 @@ module Eco
12
12
  !!required
13
13
  end
14
14
 
15
+ def enviro_subpaths
16
+ self['enviro_subpaths'] ||= {}
17
+ end
18
+
15
19
  def enviro_subpath
16
20
  enviro_subpaths[config.active_enviro]
17
21
  end