eco-helpers 2.4.8 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -1
  3. data/eco-helpers.gemspec +17 -17
  4. data/lib/eco/api/common/class_auto_loader.rb +8 -3
  5. data/lib/eco/api/common/loaders/base.rb +5 -1
  6. data/lib/eco/api/common/loaders/case_base.rb +2 -3
  7. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +97 -47
  8. data/lib/eco/api/common/people/default_parsers/select_parser.rb +2 -2
  9. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +0 -1
  10. data/lib/eco/api/common/people/entry_factory.rb +13 -8
  11. data/lib/eco/api/common/people/person_attribute_parser.rb +1 -1
  12. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +2 -2
  13. data/lib/eco/api/common/people/person_parser.rb +1 -1
  14. data/lib/eco/api/common/session/base_session.rb +1 -2
  15. data/lib/eco/api/common/session/environment.rb +6 -10
  16. data/lib/eco/api/common/session/helpers/prompt_user.rb +18 -18
  17. data/lib/eco/api/common/session/logger.rb +2 -2
  18. data/lib/eco/api/common/session/mailer.rb +1 -3
  19. data/lib/eco/api/common/session/s3_uploader.rb +1 -3
  20. data/lib/eco/api/common/session/sftp.rb +6 -4
  21. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +5 -4
  22. data/lib/eco/api/error.rb +5 -5
  23. data/lib/eco/api/session/config/api.rb +4 -2
  24. data/lib/eco/api/usecases/base_case.rb +0 -2
  25. data/lib/eco/api/usecases/base_io.rb +0 -3
  26. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +1 -1
  27. data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +1 -2
  28. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +0 -1
  29. data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +0 -1
  30. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +1 -1
  31. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +0 -2
  32. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +0 -1
  33. data/lib/eco/api/usecases/ooze_samples.rb +0 -1
  34. data/lib/eco/api/usecases/use_case.rb +30 -1
  35. data/lib/eco/api/usecases/use_case_chain.rb +1 -4
  36. data/lib/eco/api/usecases/use_case_io.rb +0 -2
  37. data/lib/eco/api/usecases.rb +4 -4
  38. data/lib/eco/api.rb +0 -2
  39. data/lib/eco/cli/config/default/options.rb +11 -1
  40. data/lib/eco/cli/scripting/arguments.rb +1 -1
  41. data/lib/eco/csv.rb +4 -7
  42. data/lib/eco/data/files/directory.rb +0 -3
  43. data/lib/eco/data/files/encoding.rb +75 -0
  44. data/lib/eco/data/files/helpers.rb +15 -37
  45. data/lib/eco/data/files.rb +1 -0
  46. data/lib/eco/data/fuzzy_match.rb +8 -4
  47. data/lib/eco/data.rb +0 -1
  48. data/lib/eco/version.rb +1 -1
  49. data/lib/eco-helpers.rb +1 -1
  50. metadata +23 -24
  51. data/lib/eco/data/crypto/encryption.rb +0 -321
  52. data/lib/eco/data/crypto.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: facf3e640f8af36beba49a9da6eb7c72cb70b4a07ef93602ee70898cce31c356
4
- data.tar.gz: 304bb16fdefd0db6ad63b524a654aed990375a24630565d59cfb6fa4470e94da
3
+ metadata.gz: b15015d62d69b57bfaef2e33cb9800786806f1796621f8a7c3fdc570bec81c99
4
+ data.tar.gz: 046b93c466ef6999e97c2d17584d4e760c3d6592783448c4fed3aed2edd3a0d2
5
5
  SHA512:
6
- metadata.gz: 6d4b1882f5c042ceeeee46bfb6e1604204092a108409c882df2f82e125259cd11551ce90e48c40cf5c7cdf50286eda42b624c9cd24d9e1ea13d4a8bb3203d9b2
7
- data.tar.gz: 91061e3b0d8caafc59fbd77ca726cf84c83d459eb1bad420932ad3482842d57acd1a38a35373a82078638b6c7e41e570a6c7f2adb84a319a38c61509555d2bc9
6
+ metadata.gz: '079b89d982758de246c8f81fcc5e8853fdcc75c217f1b7e417408b9234a8a942aa874e77705fe62c0863699bf72dcf666297894b6febdb3f47bcb740af2d438e'
7
+ data.tar.gz: 7feaa9e6022432a50c3fab188283e6af6566a8fe9de7b84fd3dcfba4584c64fd02cc5d926f3f50db8a44f139138844438345222d941b7407a6f4369b257ca070
data/CHANGELOG.md CHANGED
@@ -1,12 +1,55 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.4.9] - 2023-04-xx
4
+ ## [2.5.2] - 2023-06-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
+ ## [2.5.1] - 2023-06-06
11
+
12
+ ### Added
13
+ - `Eco::API::Common::Session:SFTP#host` method
14
+ - New options to control csv headers check (`Eco::API::Common::People::DefaultParsers::CSVParser`)
15
+ - `Eco::API::Common::Loaders::CaseBase` add to the setter the `@usecase`
16
+ - Implemented via `Eco::API::UseCases::UseCase`
17
+
18
+ ### Changed
19
+ - Dry out dependency loading.
20
+ - `ecoportal-api` **gem** remains as eager loading.
21
+ - Patch `Ecoportal::API::V1::Person` with `include`
22
+ - Upgraded `ecoportal-api-graphql` **gem**
23
+ - `Eco::API::Common::People::PersonEntryAttributeMapper`
24
+ - Switched reversed attr defs warning to `info` logging level.
25
+ - `Eco::API::Common::DefaultParsers::SelectParser`
26
+ - When there is dependency with the hash of options, it should return nil when the option is unknown.
27
+
28
+ ### Fixed
29
+ - Tidied up file encoding when getting content.
30
+ - This fixes `Eco::CSV::read`
31
+ - `Eco::API::Common::People::DefaultParsers::CSVParser` made some refactor.
32
+
33
+ ## [2.4.9] - 2023-04-17
34
+
35
+ ### Added
36
+ - `Eco::API::UseCases#source_object` to retrieve the original use case definition object
37
+ - This allows the `Eco::API::UseCases::UseCase` object to access the object that defined the usecase and initialize `@session`.
38
+ - It now can know what `type` of use case created the `@callback`
39
+ - Next steps with this may be play a bit with the `aritity` of the `@callback` block, allow parsers to skip the serializer definition (so the default one runs), etc.
40
+ - `Eco::API::Common::Loaders::Base` the above feature allowed to initialize the `@options`, and therefore...
41
+ - `#options` method **added** (based on `@options` instance var)
42
+
43
+ ### Changed
44
+ - `Eco::API::Common::Loaders::Base`
45
+ - `#session` method is based on `@session` instance var, which allows to override without having to redefine `session` (`attr_reader :session` is no longer necessary)
46
+ - Softened max version of **gem** dependencies
47
+ - Upgraded self-managed **gem** dependencies
48
+
49
+ ### Fixed
50
+ - `Eco::API::Common::ClassAutoLoader::autoload_children`
51
+ - Skip `singleton_classes`
52
+
10
53
  ## [2.4.8] - 2023-04-03
11
54
 
12
55
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -24,24 +24,24 @@ 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", "< 2.5"
28
- spec.add_development_dependency "rspec", ">= 3.10.0", "< 3.11"
29
- spec.add_development_dependency "rake", ">= 13.0.3", "< 13.1"
30
- spec.add_development_dependency "yard", ">= 0.9.26", "< 0.10"
31
- spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
27
+ spec.add_development_dependency "bundler", ">= 2.4.8", "< 3"
28
+ spec.add_development_dependency "rspec", ">= 3.10.0", "< 4"
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"
32
32
 
33
- spec.add_dependency 'ecoportal-api', '>= 0.9.3', '< 0.10'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 1.1.1', '< 1.2'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.5', '< 0.4'
33
+ spec.add_dependency 'ecoportal-api', '>= 0.9.4', '< 0.10'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 1.1.2', '< 1.2'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.7', '< 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
- spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
39
- spec.add_dependency 'net-sftp', '>= 3.0.0', '< 3.1'
40
- spec.add_dependency 'hashdiff', '>= 1.0.1', '< 1.1'
41
- 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'
45
- spec.add_dependency 'roo-xls', '>= 1.2.0', '< 1.3'
46
- spec.add_dependency 'docx', '>= 0.6.2', '< 0.7'
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'
41
+ 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'
45
+ spec.add_dependency 'roo-xls', '>= 1.2.0', '< 1.3'
46
+ spec.add_dependency 'docx', '>= 0.6.2', '< 0.7'
47
47
  end
@@ -80,8 +80,14 @@ module Eco
80
80
  return false if pending_children.empty?
81
81
  @loading_children = true
82
82
  pending_children.each do |klass|
83
- @child = klass.new(object)
84
- autoloaded_children.push(klass)
83
+ begin
84
+ @child = klass.new(object)
85
+ rescue TypeError => e
86
+ # Can't create from this class (must be the singleton class)
87
+ # Just ignore
88
+ ensure
89
+ autoloaded_children.push(klass)
90
+ end
85
91
  end
86
92
  @loading_children = false
87
93
  true
@@ -102,7 +108,6 @@ module Eco
102
108
  def new_classes
103
109
  ObjectSpace.each_object(::Class).to_a - known_classes
104
110
  end
105
-
106
111
  end
107
112
  end
108
113
  end
@@ -36,7 +36,11 @@ module Eco
36
36
  private
37
37
 
38
38
  def session
39
- ASSETS.session
39
+ @session ||= ASSETS.session
40
+ end
41
+
42
+ def options
43
+ @options ||= {}
40
44
  end
41
45
 
42
46
  def config
@@ -3,7 +3,6 @@ module Eco
3
3
  module Common
4
4
  module Loaders
5
5
  class CaseBase < Loaders::Base
6
-
7
6
  class << self
8
7
  attr_writer :name, :type
9
8
 
@@ -19,13 +18,13 @@ module Eco
19
18
  def name_only_once!
20
19
  raise "You have already declared #{self} or you are trying to give it a name twice" if @name
21
20
  end
22
-
23
21
  end
24
22
 
23
+ attr_reader :usecase
24
+
25
25
  def name
26
26
  self.class.name
27
27
  end
28
-
29
28
  end
30
29
  end
31
30
  end
@@ -3,7 +3,8 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
3
3
 
4
4
  def parser(data, deps)
5
5
  Eco::CSV.parse(data, headers: true, skip_blanks: true).tap do |table|
6
- check_headers(table) if deps[:check_headers] && !options.dig(:input, :skip_header_check)
6
+ require_headers!(table)
7
+ check_headers(table) if deps[:check_headers] && check_headers?
7
8
  end.each_with_object([]) do |row, arr_hash|
8
9
  row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
9
10
  next if attr.to_s.strip.empty?
@@ -26,6 +27,26 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
26
27
 
27
28
  private
28
29
 
30
+ def abort(message)
31
+ logger.error(message)
32
+ exit(1)
33
+ end
34
+
35
+ def require_headers!(table)
36
+ headers = table.headers
37
+ abort("Missing headers in CSV") unless headers && !headers.empty?
38
+ empty = []
39
+ with_value = headers.each_with_index do |header, idx|
40
+ empty << idx if header.to_s.strip.empty?
41
+ end
42
+ abort("Empty headers in column(s): #{empty.join(', ')}") unless empty.empty?
43
+ true
44
+ end
45
+
46
+ def check_headers?
47
+ !options.dig(:input, :header_check, :skip)
48
+ end
49
+
29
50
  def options
30
51
  ASSETS.cli.options
31
52
  end
@@ -43,29 +64,54 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
43
64
  end
44
65
 
45
66
  def check_headers(table)
46
- headers = table.headers
47
- missing = missing_headers(headers)
48
- unknown = unknown_headers(headers)
49
- unless missing.empty? && unknown.empty?
50
- msg = "Detected possible HEADER ISSUES !!!\n"
51
- msg << "There might be Missing or Wrong HEADER names in the CSV file:\n"
52
- msg << " * UNKNOWN (or not used?): #{unknown}\n" unless unknown.empty?
53
- msg << " * MISSING DIRECT: #{missing[:direct]}\n" unless (missing[:direct] || []).empty?
54
- unless (data = missing[:indirect] || []).empty?
55
- msg << " * MISSING INDIRECT:\n"
56
- data.each do |ext, info|
57
- msg << " - '#{ext}' => "
58
- msg << (info[:attrs] || {}).map do |status, attrs|
59
- if status == :inactive
60
- "makes inactive: #{attrs}"
61
- elsif status == :active
62
- "there could be missing info in: #{attrs}"
63
- end
64
- end.compact.join("; ") + "\n"
65
- end
67
+ headers = table.headers
68
+ unmatch = []
69
+ unmatch = unmatched_headers(headers) if options.dig(:input, :header_check, :order)
70
+ missing = missing_headers(headers)
71
+ unknown = unknown_headers(headers)
72
+ criteria = [unknown, missing[:direct], missing[:indirect], unmatch]
73
+ return if criteria.all?(&:empty?)
74
+
75
+ msg = "Detected possible HEADER ISSUES !!!\n"
76
+
77
+ # requires exact match
78
+ unless unmatch.empty?
79
+ msg << "CSV headers do NOT exactly match the expected:\n"
80
+ msg << " * Expected: #{known_headers}\n"
81
+ expected, given = unmatch.first
82
+ msg << " * First unmatch => Given: '#{given}' where expected '#{expected}'\n"
83
+ missed = known_headers - headers
84
+ unless missed.empty?
85
+ msg << " * Missing headers:\n"
86
+ msg << " - #{missed.join("\n - ")}\n"
66
87
  end
67
- logger.warn(msg)
68
- sleep(2)
88
+ end
89
+ msg << "Missing or Wrong HEADER names in the CSV file:\n"
90
+ msg << " * UNKNOWN (or not used?): #{unknown}\n" unless unknown.empty?
91
+ msg << " * MISSING HEADER: #{missing[:direct]}\n" unless missing[:direct].empty?
92
+ unless (data = missing[:indirect]).empty?
93
+ msg << " * MISSING INDIRECTLY:\n"
94
+ data.each do |ext, info|
95
+ msg << " - '#{ext}' => "
96
+ msg << (info[:attrs] || {}).map do |status, attrs|
97
+ if status == :inactive
98
+ "makes inactive: #{attrs}"
99
+ elsif status == :active
100
+ "there could be missing info in: #{attrs}"
101
+ end
102
+ end.compact.join("; ") + "\n"
103
+ end
104
+ end
105
+ logger.warn(msg)
106
+ if options.dig(:input, :header_check, :must_be_valid)
107
+ abort("There were issues identified on the CSV header names. Aborting...")
108
+ end
109
+ sleep(2)
110
+ end
111
+
112
+ def unmatched_headers(headers)
113
+ known_headers.zip(headers).reject do |(expected, given)|
114
+ expected == given
69
115
  end
70
116
  end
71
117
 
@@ -82,27 +128,28 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
82
128
  ext_present = known_headers_present(int_head) | ext
83
129
  ext_miss = known_headers - ext_present
84
130
 
85
- ext_miss.each_with_object({}) do |ext, missing|
86
- next unless int = fields_mapper.to_internal(ext)
87
- if all_internal_attrs.include?(int)
88
- missing[:direct] ||= []
89
- missing[:direct] << ext
90
- end
91
- related_attrs_requirements = required_attrs.values.select do |req|
92
- dep = req.dependant?(int)
93
- affects = dep && !int_head.include?(int)
94
- in_header = int_head.include?(req.attr)
95
- affects || (dep && !in_header)
96
- end
97
- next if related_attrs_requirements.empty?
98
- missing[:indirect] ||= {}
99
- data = missing[:indirect][ext] = {}
100
- data[:int] = int
101
- data[:attrs] = {}
102
- related_attrs_requirements.each_with_object(data[:attrs]) do |req, attrs|
103
- status = req.active?(*int_head) ? :active : :inactive
104
- attrs[status] ||= []
105
- attrs[status] << req.attr
131
+ {
132
+ direct: [],
133
+ indirect: {}
134
+ }.tap do |missing|
135
+ ext_miss.each do |ext|
136
+ next unless int = fields_mapper.to_internal(ext)
137
+ missing[:direct] << ext if all_internal_attrs.include?(int)
138
+ related_attrs_requirements = required_attrs.values.select do |req|
139
+ dep = req.dependant?(int)
140
+ affects = dep && !int_head.include?(int)
141
+ in_header = int_head.include?(req.attr)
142
+ affects || (dep && !in_header)
143
+ end
144
+ next if related_attrs_requirements.empty?
145
+ data = missing[:indirect][ext] = {}
146
+ data[:int] = int
147
+ data[:attrs] = {}
148
+ related_attrs_requirements.each_with_object(data[:attrs]) do |req, attrs|
149
+ status = req.active?(*int_head) ? :active : :inactive
150
+ attrs[status] ||= []
151
+ attrs[status] << req.attr
152
+ end
106
153
  end
107
154
  end
108
155
  end
@@ -114,8 +161,11 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
114
161
  end
115
162
  end
116
163
 
164
+ # Scopes what internal attrs appear in headers as they are
117
165
  def internal_present_or_active(headers, inactive_requirements = {})
118
- hint = headers & all_internal_attrs
166
+ # internal attrs that are not being mapped
167
+ int_all = all_internal_attrs.reject {|i| fields_mapper.external?(i)}
168
+ hint = headers & int_all
119
169
  hext = headers - hint
120
170
  int_present = hint + hext.map {|e| fields_mapper.to_internal(e)}.compact
121
171
 
@@ -142,8 +192,9 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
142
192
  int_present
143
193
  end
144
194
 
195
+ # The csv header names as expected
145
196
  def known_headers
146
- @known_headers ||= fields_mapper.list(:external).compact
197
+ @known_headers ||= fields_mapper.list(:external).compact.uniq
147
198
  end
148
199
 
149
200
  def fields_mapper
@@ -167,5 +218,4 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
167
218
  def person_parser
168
219
  session.entry_factory.person_parser
169
220
  end
170
-
171
221
  end
@@ -11,9 +11,9 @@ module Eco
11
11
  options_hash = deps[:select_hashes][deps["attr"]]
12
12
  next value if !options_hash
13
13
  if value.is_a?(Array)
14
- value.map { |v| options_hash[v&.downcase.strip] || v }
14
+ value.map { |v| options_hash[v&.downcase.strip] }.compact
15
15
  elsif value
16
- options_hash[value&.downcase.strip] || value
16
+ options_hash[value&.downcase.strip]
17
17
  end
18
18
  end.def_serializer do |value|
19
19
  value
@@ -64,5 +64,4 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
64
64
  require 'roo-xls'
65
65
  already_required = true
66
66
  end
67
-
68
67
  end
@@ -86,10 +86,10 @@ module Eco
86
86
  # @option options [Boolean] :check_headers signals if the `csv` file headers should be expected.
87
87
  # @return [Eco::API::Common::People::Entries] collection of `Eco::API::Common::People::PersonEntry`.
88
88
  def entries(data: (no_data = true; nil), file: (no_file = true; nil), format: (no_format = true; nil), **options)
89
- fatal("You should at least use data: or file:, but not both") if no_data == no_file
89
+ fatal("You should at least use data: or file:, but not both") if no_data == no_file
90
90
  fatal("You must specify a valid format: (symbol) when you use file.") if file && no_format
91
- fatal("Format should be a Symbol. Given '#{format}'") if format && !format.is_a?(Symbol)
92
- fatal("There is no parser/serializer for format ':#{format.to_s}'") unless no_format || @person_parser.defined?(format)
91
+ fatal("Format should be a Symbol. Given '#{format}'") if format && !format.is_a?(Symbol)
92
+ fatal("There is no parser/serializer for format ':#{format.to_s}'") unless no_format || @person_parser.defined?(format)
93
93
 
94
94
  options.merge!(content: data) unless no_data
95
95
  options.merge!(file: file) unless no_file
@@ -113,9 +113,8 @@ module Eco
113
113
  # Get content only when it's not :xls
114
114
  # note: even if content was provided, file takes precedence
115
115
  if (format != :xls) && file
116
- content = get_file_content(file, encoding)
116
+ content = get_file_content(file, encoding: encoding)
117
117
  end
118
- #content = get_file_content(file, format, encoding) if (format != :xls) && file
119
118
 
120
119
  case content
121
120
  when Hash
@@ -129,15 +128,16 @@ module Eco
129
128
  case sample
130
129
  when Hash, Array, ::CSV::Row
131
130
  Eco::CSV::Table.new(content).to_array_of_hashes
131
+ when NilClass
132
+ abort("There is NO input data")
132
133
  else
133
- logger.error("Input content 'Array' of '#{sample.class}' is not supported.")
134
+ abort("Input content 'Array' of '#{sample.class}' is not supported.")
134
135
  end
135
136
  else
136
137
  if file && format == :xls
137
138
  person_parser.parse(format, file)
138
139
  else
139
- logger.error("Could not obtain any data out of these: #{kargs}. Given content: '#{content.class}'")
140
- exit(1)
140
+ abort("Could not obtain any data out of these: #{kargs}. Given content: '#{content.class}'")
141
141
  end
142
142
  end.tap do |out_array|
143
143
  start_from_two = (format == :csv) || format == :xls
@@ -189,6 +189,11 @@ module Eco
189
189
 
190
190
  private
191
191
 
192
+ def abort(message)
193
+ logger.error(message)
194
+ exit(1)
195
+ end
196
+
192
197
  def fatal(msg)
193
198
  logger.fatal(msg)
194
199
  raise msg
@@ -11,7 +11,7 @@ module Eco
11
11
  # @return [RequiredAttrs]
12
12
  def required_attrs
13
13
  @required_attrs ||= @dependencies[:required_attrs]
14
- #@required_attrs ||= RequiredAttrs.new(attr, :unkown, [attr])
14
+ #@required_attrs ||= RequiredAttrs.new(attr, :unknown, [attr])
15
15
  end
16
16
 
17
17
  # @see Eco::Language::Models::ParserSerializer#def_parser
@@ -133,7 +133,7 @@ module Eco
133
133
  attr = @attr_map.to_internal(value.strip)
134
134
  when @attr_map.internal?(value) || @attr_map.internal?(value.strip) || @attr_map.internal?(value.strip.downcase)
135
135
  unless cached_warning("external", "reversed", value)
136
- logger.warn("The mapper [external, internal] attribute names may be declared reversedly for EXTERNAL attribute: '#{value}'")
136
+ logger.info("The mapper [external, internal] attribute names may be declared reversedly for EXTERNAL attribute: '#{value}'")
137
137
  end
138
138
  end
139
139
  end
@@ -172,7 +172,7 @@ module Eco
172
172
  attr = @attr_map.to_external(value.strip)
173
173
  when @attr_map.external?(value) || @attr_map.external?(value.strip) || @attr_map.external?(value.strip.downcase)
174
174
  unless cached_warning("internal", "reversed", value)
175
- logger.warn("The mapper [external, internal] attribute names may be declared reversedly for INTERNAL attribute: '#{value}'")
175
+ logger.info("The mapper [external, internal] attribute names may be declared reversedly for INTERNAL attribute: '#{value}'")
176
176
  end
177
177
  end
178
178
  end
@@ -174,7 +174,7 @@ module Eco
174
174
 
175
175
  # Helper to define and associate a parser/serializer to a type or attribute.
176
176
  # @raise [Exception] if trying to define a parser/serializer for:
177
- # - an unkown attribute (`String`)
177
+ # - an unknown attribute (`String`)
178
178
  # - an unrecognized type or format (`Symbol`)
179
179
  # @param attr [String] type (`Symbol`) or attribute (`String`) to define the parser/serializer to.
180
180
  # @param dependencies [Hash] dependencies to be used when calling the parser/serializer.
@@ -12,7 +12,7 @@ module Eco
12
12
  alias_method :fm, :file_manager
13
13
 
14
14
  include Session::Helpers
15
-
15
+
16
16
  def initialize(e)
17
17
  raise "Expected object Eco::API::Common::Session::Environment. Given: #{e.class}" unless e.is_a?(Environment)
18
18
  self.environment = e
@@ -72,7 +72,6 @@ module Eco
72
72
  logger.fatal(msg)
73
73
  raise msg
74
74
  end
75
-
76
75
  end
77
76
  end
78
77
  end
@@ -24,9 +24,8 @@ module Eco
24
24
  end
25
25
 
26
26
  def mailer
27
- if mailer?
28
- @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
29
- end
27
+ return nil unless mailer?
28
+ @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
30
29
  end
31
30
 
32
31
  def mailer?
@@ -34,9 +33,8 @@ module Eco
34
33
  end
35
34
 
36
35
  def sftp
37
- if sftp?
38
- @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
39
- end
36
+ return nil unless sftp?
37
+ @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
40
38
  end
41
39
 
42
40
  def sftp?
@@ -44,9 +42,8 @@ module Eco
44
42
  end
45
43
 
46
44
  def s3uploader
47
- if s3uploader?
48
- @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
49
- end
45
+ return nil unless s3uploader?
46
+ @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
50
47
  end
51
48
 
52
49
  def s3uploader?
@@ -56,7 +53,6 @@ module Eco
56
53
  def api(version: nil)
57
54
  config.api(logger, version: version)
58
55
  end
59
-
60
56
  end
61
57
  end
62
58
  end
@@ -1,31 +1,31 @@
1
- require 'timeout'
2
1
  module Eco
3
2
  module API
4
3
  module Common
5
4
  module Session
6
5
  module Helpers
7
6
  module PromptUser
8
-
7
+ # Prompts user for input with option for default on timeout.
9
8
  def prompt_user(question, default:, explanation: "", timeout: nil)
10
- response = if config.run_mode_remote?
11
- default
12
- else
13
- puts explanation
14
- print "#{question} "
15
- if timeout
16
- begin
17
- Timeout::timeout(timeout) { STDIN.gets.chop }
18
- rescue Timeout::Error
19
- default
20
- end
21
- else
22
- STDIN.gets.chop
23
- end
24
- end
9
+ require 'timeout'
10
+ response = \
11
+ if config.run_mode_remote?
12
+ default
13
+ else
14
+ puts explanation
15
+ print "#{question} "
16
+ if timeout
17
+ begin
18
+ Timeout::timeout(timeout) { STDIN.gets.chop }
19
+ rescue Timeout::Error
20
+ default
21
+ end
22
+ else
23
+ STDIN.gets.chop
24
+ end
25
+ end
25
26
  return response unless block_given?
26
27
  yield(response)
27
28
  end
28
-
29
29
  end
30
30
  end
31
31
  end
@@ -57,8 +57,8 @@ module Eco
57
57
  return log(:fatal, *args, &block)
58
58
  end
59
59
 
60
- def unkown(msg, &block)
61
- return log(:unkown, *args, &block)
60
+ def unknown(msg, &block)
61
+ return log(:unknown, *args, &block)
62
62
  end
63
63
 
64
64
  def << (msg)
@@ -1,5 +1,3 @@
1
- require 'aws-sdk-ses'
2
-
3
1
  module Eco
4
2
  module API
5
3
  module Common
@@ -42,6 +40,7 @@ module Eco
42
40
  private
43
41
 
44
42
  def ses
43
+ require 'aws-sdk-ses'
45
44
  begin
46
45
  @ses ||= Aws::SES::Client.new(
47
46
  access_key_id: fetch_access_key_id,
@@ -98,7 +97,6 @@ module Eco
98
97
  def fetch_message_id_domain
99
98
  config.mailer.message_id_domain
100
99
  end
101
-
102
100
  end
103
101
  end
104
102
  end
@@ -1,5 +1,3 @@
1
- require 'aws-sdk-s3'
2
-
3
1
  module Eco
4
2
  module API
5
3
  module Common
@@ -75,6 +73,7 @@ module Eco
75
73
  end
76
74
 
77
75
  def bucket
76
+ require 'aws-sdk-s3'
78
77
  begin
79
78
  @bucket ||= Aws::S3::Resource.new(
80
79
  access_key_id: fetch_access_key_id,
@@ -128,7 +127,6 @@ module Eco
128
127
  def fetch_region
129
128
  config.s3storage.region || ENV['AWS_REGION']
130
129
  end
131
-
132
130
  end
133
131
  end
134
132
  end