eco-helpers 2.0.14 → 2.0.15

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: 697d71754e809691a39f62a86d5fc46e2988578c19c965945e1c06ea73b290b6
4
- data.tar.gz: 01ef5ca1a9bcf941d44b5f7088f54dd9c2cba950cc562ed0516400811df60f12
3
+ metadata.gz: 9ea76fb273e572c873b2f23348c54b56fd4e51cd39d9bf1109ddbc4594ba260f
4
+ data.tar.gz: 56d64b1eb28202f4bd18997ff8854fdd6ae36c758217796f4739012f59d4ef5c
5
5
  SHA512:
6
- metadata.gz: b24db6ddf741e3f0dcc3f080dba19132d7926c85cf211ae0f98c090c7a3cd93f513b6e977ac21ca24d5c2092d524cc1e7ef3d04250bb29ae672400623c823964
7
- data.tar.gz: 9585e95676aab71322af2f174d06aed7d6226502bed1e2560cfd0915643e682c02fb857c33310f7c5f1b6d083b83267d14194f0f1e315c940048ef1c3c43faff
6
+ metadata.gz: bf49254f9b3f162f278d65f734fba3d3f683906cb1202df4d4cc4f7a90f2d663655e5168cf5bdea13d78b63d8ece32bcd22541655b001f3a9bfad429d89d2de8
7
+ data.tar.gz: 3dcd85969e34079aa050546e427ebe0d28cb7ec358b121f066cd603af23c9c44bb05551ce8db061f1721832981c2b74c1a46aa095c031f9ea0fb8b29b1b65310
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.14] - 2021-03-xx
4
+ ## [2.0.15] - 2021-04-xx
5
+
6
+ ### Added
7
+ - Use case `Eco::API::UseCases::DefaultCases::SupersHierarchy`, invokable via `-supers-hiearchy`
8
+ ### Changed
9
+ ### Fixed
10
+ - `eco/cli/config/default/workflow.rb` prevent `rescue` looping
11
+
12
+ ## [2.0.14] - 2021-04-15
5
13
 
6
14
  ### Added
7
15
  - `Eco::API::UseCases::DefaultCases::ToCsvCase` added option `-internal-names` to avoid overriding data on export
@@ -32,6 +32,7 @@ require_relative 'default_cases/reset_landing_page_case'
32
32
  require_relative 'default_cases/restore_db_case'
33
33
  require_relative 'default_cases/set_default_tag_case'
34
34
  require_relative 'default_cases/set_supervisor_case'
35
+ require_relative 'default_cases/supers_hierarchy_case'
35
36
  require_relative 'default_cases/switch_supervisor_case'
36
37
  require_relative 'default_cases/to_csv_case'
37
38
  require_relative 'default_cases/to_csv_detailed_case'
@@ -0,0 +1,59 @@
1
+ class Eco::API::UseCases::DefaultCases::SupersHierarchy < Eco::API::Common::Loaders::UseCase
2
+ name "supers-hierarchy"
3
+ type :export
4
+
5
+ attr_reader :session, :people, :options
6
+
7
+ def main(people, session, options, usecase)
8
+ @session = session; @options = options; @people = people
9
+
10
+ save!(hierarchy)
11
+ exit(0)
12
+ end
13
+
14
+ private
15
+
16
+ def hierarchy
17
+ Eco::API::Common::People::SupervisorHelpers.supervisors_tree(people)
18
+ end
19
+
20
+ def file
21
+ @file ||= options.dig(:output, :file) || "supers_hierarchy.txt"
22
+ end
23
+
24
+ def save!(data)
25
+ ext = File.extname(file).downcase.delete(".")
26
+
27
+ File.open(file, "w") do |fd|
28
+ if ext == "txt"
29
+ create_file(data, file: file, format: :txt)
30
+ elsif ext == "html"
31
+ puts "html is still not supported"
32
+ exit(1)
33
+ create_file(data, file: file, format: :html)
34
+ elsif ext == "json"
35
+ puts "json is still not supported"
36
+ exit(1)
37
+ create_file(data, file: file, format: :json)
38
+ end
39
+ end
40
+ end
41
+
42
+ def create_file(tree, file:, format: :txt)
43
+ File.open(file, "w") do |fd|
44
+ fd << tree_to_str(tree, format: format)
45
+ end
46
+ puts "Generated file #{file}"
47
+ end
48
+
49
+ def tree_to_str(tree, lev: 0, format: :txt)
50
+ raise "Required Hash tree structure. Given: #{tree.class}" unless tree.is_a?(Hash)
51
+ "".tap do |str|
52
+ tree.each do |entry, subtree|
53
+ str << "#{" " * lev}#{(lev > 0)? "+-#{lev}- " : ""}#{entry.name} (#{entry.external_id}|#{entry.email}|#{entry.id})\n"
54
+ str << tree_to_str(subtree, lev: lev + 1, format: format) unless !subtree || subtree.empty?
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -1,6 +1,12 @@
1
1
  ASSETS.cli.config do |cnf|
2
2
  cnf.usecases do |cases|
3
3
 
4
+ desc = "Draws the Supervisors hiearchy in a file (use option -to file.ext)"
5
+ cases.add("-supers-hierarchy", :export, desc, case_name: "supers-hierarchy") do |people, session, options|
6
+ file = (SCR.get_arg("-to") && SCR.get_file("-to", required: true, should_exist: false)) || "supers_hierarchy.txt"
7
+ options.deep_merge!(output: {file: file})
8
+ end
9
+
4
10
  desc = "It exports to a CSV the (filtered) people"
5
11
  cases.add("-people-to-csv", :export, desc) do |people, session, options|
6
12
  file = SCR.get_file("-people-to-csv", required: true, should_exist: false)
@@ -2,8 +2,13 @@ ASSETS.cli.config do |config|
2
2
  ASSETS.config.workflow do |wf|
3
3
 
4
4
  io = nil
5
+ rescued = false
6
+
5
7
  # default rescue
6
8
  wf.rescue do |exception, io|
9
+ next io if rescued
10
+ rescued = true
11
+
7
12
  io.session.logger.debug(exception.patch_full_message)
8
13
  wf.run(:close, io: io)
9
14
  io
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.14"
2
+ VERSION = "2.0.15"
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.0.14
4
+ version: 2.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -399,6 +399,7 @@ files:
399
399
  - lib/eco/api/usecases/default_cases/restore_db_case.rb
400
400
  - lib/eco/api/usecases/default_cases/set_default_tag_case.rb
401
401
  - lib/eco/api/usecases/default_cases/set_supervisor_case.rb
402
+ - lib/eco/api/usecases/default_cases/supers_hierarchy_case.rb
402
403
  - lib/eco/api/usecases/default_cases/switch_supervisor_case.rb
403
404
  - lib/eco/api/usecases/default_cases/to_csv_case.rb
404
405
  - lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb