eco-helpers 2.4.5 → 2.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 333d58d63c6ffad6b06865c89dce3e48a50347ba998361f34eb9a2e230ea83f2
4
- data.tar.gz: 7be152e20c00765217b6650790dfd4aeba729bb614e6d0928a7e7ea82d94de33
3
+ metadata.gz: 0ab1e50c5ccc57fd84bd6b21b40a9d455455e3457c89248f7bf60177fe82293a
4
+ data.tar.gz: 169a31ded9574a5fd8a135a0cfe3f388fe71c48e87f7f67969e12036ba40ab3f
5
5
  SHA512:
6
- metadata.gz: 3cb79f7d5429bf4c3cd8b8b37cbbdb2b8208da2161559fb6a09b08a67cea1ded2d08355928af4ee136b39bc10fda3f82ece275f5991c65bfcf41c4290d7d7269
7
- data.tar.gz: 78723001238f02cac999e2af5200e1e13f444572366291357a70ec951732ded65bd708be9b6c0259a9e6bf797fc5c803df17a28167d01b1bf1223900f8226cc7
6
+ metadata.gz: 7de4657000ee0181e9c7dcea3536365c5a66fc26d5b25999715129ce4ebed459ba67042de42736b96879b617aba2adc063f92403f0ff063cac13fd5301562191
7
+ data.tar.gz: e9518629a51f623b07d795eedad394682b53bc23edf1389cb2185f34519ccaed8cf2c746eba8c8ae0c4e12b41068b7444f2f6f263e3a30cd5ab91aa45be09185
data/CHANGELOG.md CHANGED
@@ -1,16 +1,45 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.4.6] - 2023-03-xx
4
+ ## [2.4.8] - 2023-04-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
+ ## [2.4.7] - 2023-04-03
11
+
12
+ ### Added
13
+ - `Eco::Data::Hashes::ArrayDiff#diffs?`
14
+ - `Eco::API::Organization::TagTree` added methods:
15
+ - `#source` => to expose the original doc
16
+ - `#all_nodes` => to implement the block call
17
+
18
+ ### Changed
19
+ - Upgraded `ecoportal-api-graphql` **gem**
20
+
21
+ ### Fixed
22
+ - `Eco::API::Session::Config::Api` **new `graphql` api** was missing `host`
23
+ - `Eco::API::UseCases::DefaultCases::CsvToTree::Helper`
24
+ - `#nodes_from_csv` assumed unique top level tag and not present
25
+ - This fix completes this feature (as top level tags were not there)
26
+
27
+ ## [2.4.6] - 2023-04-02
28
+
29
+ ### Added
30
+ - `Eco::API::Organization::TagTree` added support for `archived_token`
31
+ - Added support for `block` in
32
+ - `Eco::API::Session#live_tree`
33
+ - `Eco::API::Session::Config::Tagtree` in `#live_trees` and `live_tree`
34
+
35
+ ### Changed
36
+ - Upgraded `ecoportal-api-graphql` **gem**
37
+
38
+
10
39
  ## [2.4.5] - 2023-03-31
11
40
 
12
41
  ### Added
13
- - `Eco::API:Organization::TagTree` support for `archived` and `weight` properties
42
+ - `Eco::API::Organization::TagTree` support for `archived` and `weight` properties
14
43
  - `Eco::Data::Hashes::ArrayDiff` and `Eco::Data::Hashes::DiffResult`
15
44
  - Enable easy comparison of array of hashes
16
45
  - Input data can be diverse
data/eco-helpers.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.9.3', '< 0.10'
34
34
  spec.add_dependency 'ecoportal-api-v2', '>= 1.1.1', '< 1.2'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.1', '< 0.4'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.5', '< 0.4'
36
36
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
37
37
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
38
38
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
@@ -5,13 +5,16 @@ module Eco
5
5
  class TagTree
6
6
  attr_accessor :id
7
7
  alias_method :tag, :id
8
- attr_accessor :name, :archived, :weight
8
+ attr_accessor :name, :weight
9
+ attr_accessor :archived, :archived_token
9
10
 
10
11
  attr_reader :parent
11
12
  attr_reader :nodes, :children_count
12
13
  attr_reader :depth, :path
13
14
  attr_reader :enviro
14
15
 
16
+ attr_reader :source
17
+
15
18
  include Enumerable
16
19
 
17
20
  # @example Node format:
@@ -41,19 +44,20 @@ module Eco
41
44
  if @source.is_a?(Array)
42
45
  @id = id
43
46
  @name = name
44
- @row_nodes = @source
47
+ @raw_nodes = @source
45
48
  else
46
49
  @id = @source.values_at('tag', 'id').compact.first&.upcase
47
50
  @name = @source['name']
48
- @archived = @source.fetch('archived', false)
49
- @weight = @source.fetch('weight', _weight)
50
- @row_nodes = @source['nodes'] || []
51
+ @archived = @source['archived'] || false
52
+ @archived_token = @source['archived_token']
53
+ @source['weight'] = @weight = @source['weight'] || _weight
54
+ @raw_nodes = @source['nodes'] || []
51
55
  end
52
56
 
53
57
  @path = path || []
54
58
  @path.push(@id) unless top?
55
59
 
56
- @nodes = @row_nodes.map.with_index do |cnode, idx|
60
+ @nodes = @raw_nodes.map.with_index do |cnode, idx|
57
61
  TagTree.new(cnode, depth: depth + 1, path: @path.dup, parent: self, _weight: idx, enviro: @enviro)
58
62
  end
59
63
 
@@ -82,10 +86,13 @@ module Eco
82
86
  # @note order is that of the parent to child relationships
83
87
  # @return [Array[]]
84
88
  def all_nodes(&block)
85
- [].tap do |all_nodes|
86
- all_nodes.push(self) unless top?
89
+ [].tap do |out_nodes|
90
+ unless top?
91
+ out_nodes.push(self)
92
+ yield(self) if block_given?
93
+ end
87
94
  nodes.each do |node|
88
- all_nodes.concat(node.all_nodes)
95
+ out_nodes.concat(node.all_nodes(&block))
89
96
  end
90
97
  end
91
98
  end
@@ -171,7 +171,7 @@ module Eco
171
171
  when :v2
172
172
  klass.new(user_key: user_key, org_key: external_key, host: host, logger: logger)
173
173
  when :graphql
174
- klass.new(org_id: org_id, email: email, pass: pass)
174
+ klass.new(host: host, org_id: org_id, email: email, pass: pass)
175
175
  end.tap do |api|
176
176
  unless !api || log_connection?
177
177
  @logger.info("Created api#{self.version(version)} connection on '#{name}' enviro, pointing to '#{host}' in '#{mode}' mode")
@@ -20,9 +20,9 @@ module Eco
20
20
  end
21
21
 
22
22
  # Among all the locations structures it selects the one with more location nodes
23
- def live_tree(enviro: nil, include_archived: false)
23
+ def live_tree(enviro: nil, include_archived: false, &block)
24
24
  return @live_tree if instance_variable_defined?(:@live_tree) && @live_tree.enviro == enviro
25
- trees = live_trees(enviro: enviro, include_archived: include_archived)
25
+ trees = live_trees(enviro: enviro, include_archived: include_archived, &block)
26
26
  @live_tree = trees.reject do |tree|
27
27
  tree.empty?
28
28
  end.max do |a,b|
@@ -36,7 +36,7 @@ module Eco
36
36
  end
37
37
 
38
38
  # Retrieves all the location structures of the organisation
39
- def live_trees(enviro: nil, include_archived: false)
39
+ def live_trees(enviro: nil, include_archived: false, &block)
40
40
  [].tap do |eco_trees|
41
41
  next unless apis.active_api.version_available?(:graphql)
42
42
  next unless graphql = apis.api(version: :graphql)
@@ -44,7 +44,7 @@ module Eco
44
44
  includeArchived: include_archived,
45
45
  includeUnpublished: false
46
46
  }
47
- next unless trees = graphql.currentOrganization.locationStructures(**kargs)
47
+ next unless trees = graphql.currentOrganization.locationStructures(**kargs, &block)
48
48
  trees.each do |tree|
49
49
  args = { enviro: enviro, id: tree.id, name: tree.name}
50
50
  eco_tree = Eco::API::Organization::TagTree.new(tree.treeify, **args)
@@ -45,8 +45,8 @@ module Eco
45
45
  end
46
46
 
47
47
  # @see Eco::API::Session::Config#live_tree
48
- def live_tree(include_archived: false)
49
- config.live_tree(enviro: enviro)
48
+ def live_tree(include_archived: false, &block)
49
+ config.live_tree(enviro: enviro, &block)
50
50
  end
51
51
 
52
52
  # @see Eco::API::Session::Config#schemas
@@ -25,11 +25,16 @@ class Eco::API::UseCases::DefaultCases::CsvToTree
25
25
  node = Node.new(i, *values)
26
26
  prev_node ||= node
27
27
 
28
- if prev_node.raw_level <= node.raw_level
28
+ # If node is nested in prev_node or is a sibling thereof
29
+ if prev_node.raw_level <= node.raw_level\
30
+ # Make sure parent is among upper level tags
29
31
  node.set_high_levels(prev_node)
30
32
  else
31
33
  if parent_node = prev_nodes[node.raw_level - 1]
32
34
  node.set_high_levels(parent_node)
35
+ elsif node.raw_level == 1
36
+ # It is expected not to have parent
37
+ #puts "Node '#{node.raw_tag}' doesn't have parent, but it's top level tag"
33
38
  else
34
39
  raise "Node '#{node.raw_tag}' (#{node.row_num} row) doesn't have parent"
35
40
  end
@@ -44,7 +44,7 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
44
44
  other_people = people.group_by_schema.values_at(*other_schemas).map(&:to_a).flatten
45
45
  if other_people.length > 3
46
46
  msg = "There are #{other_people.length} people in schemas other than #{active_schema.name}."
47
- msg << " Please, use the filter option '-schema_id SchemaName' for the 'hris' case to only include those of that schema"
47
+ msg << " Please, use the filter option '-schema-id SchemaName' for the 'hris' case to only include those of that schema"
48
48
  msg << " in the current update. The HRIS case identifies people that are not in the file as leavers"
49
49
  msg << " (as it will remove the account of all the people of other schemas if they are not in the input file)."
50
50
  msg << "\n For example: -schema-id '#{active_schema.name.downcase}'"
@@ -56,15 +56,24 @@ module Eco
56
56
  # - It also allows to know the original value
57
57
  # @return [Hash] where `key` is the key of the record, and `value` a `DiffResult` object
58
58
  def diffs
59
- @diffs ||= paired_sources.each_with_object([]) do |(src1, src2), diffs|
59
+ @diffs ||= source_results.select do |res|
60
+ res.diff?
61
+ end
62
+ end
63
+
64
+ # @return [Boolean] wheter or not there are differences.
65
+ def diffs?
66
+ !diffs.empty?
67
+ end
68
+
69
+ def source_results
70
+ @source_results ||= paired_sources.each_with_object([]) do |(src1, src2), res|
60
71
  args = {
61
72
  key: key,
62
73
  compare: compared_attrs,
63
74
  case_sensitive: case_sensitive?
64
75
  }
65
- diff_result_class.new(src1, src2, **args).tap do |res|
66
- diffs << res if res.diff?
67
- end
76
+ res << diff_result_class.new(src1, src2, **args)
68
77
  end
69
78
  end
70
79
 
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.4.5"
2
+ VERSION = "2.4.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.5
4
+ version: 2.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -156,7 +156,7 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.3.1
159
+ version: 0.3.5
160
160
  - - "<"
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0.4'
@@ -166,7 +166,7 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 0.3.1
169
+ version: 0.3.5
170
170
  - - "<"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0.4'