eco-helpers 3.0.37 → 3.1.1
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/.rubocop.yml +1 -0
- data/CHANGELOG.md +116 -1
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +2 -0
- data/lib/eco/api/common/loaders/config/block.rb +78 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +39 -7
- data/lib/eco/api/common/loaders/config.rb +3 -26
- data/lib/eco/api/common/loaders/error_handler.rb +2 -0
- data/lib/eco/api/common/loaders/parser.rb +1 -4
- data/lib/eco/api/common/people/entries.rb +23 -6
- data/lib/eco/api/common/people/entry_factory.rb +1 -1
- data/lib/eco/api/common/people/person_entry.rb +104 -27
- data/lib/eco/api/common/people/person_parser.rb +50 -16
- data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
- data/lib/eco/api/common/session/base_session.rb +75 -81
- data/lib/eco/api/common/session/environment.rb +49 -55
- data/lib/eco/api/common/session/file_manager.rb +132 -135
- data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
- data/lib/eco/api/common/session/helpers.rb +10 -15
- data/lib/eco/api/common/session/logger/cache.rb +89 -96
- data/lib/eco/api/common/session/logger/channels.rb +24 -32
- data/lib/eco/api/common/session/logger/log.rb +38 -46
- data/lib/eco/api/common/session/logger.rb +50 -54
- data/lib/eco/api/common/session/mailer/aws_provider.rb +63 -71
- data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
- data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
- data/lib/eco/api/common/session/mailer.rb +78 -83
- data/lib/eco/api/common/session/s3_uploader.rb +132 -138
- data/lib/eco/api/common/session/sftp.rb +202 -208
- data/lib/eco/api/common.rb +0 -3
- data/lib/eco/api/custom/mailer.rb +4 -2
- data/lib/eco/api/error/handlers.rb +1 -1
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
- data/lib/eco/api/microcases/people/manage/search.rb +1 -1
- data/lib/eco/api/organization/people/similarity.rb +3 -3
- data/lib/eco/api/session/batch/base_policy.rb +42 -27
- data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
- data/lib/eco/api/session/batch/launcher.rb +16 -3
- data/lib/eco/api/session/config/api.rb +4 -3
- data/lib/eco/api/session/config/apis/one_off.rb +1 -1
- data/lib/eco/api/session/config/files.rb +13 -12
- data/lib/eco/api/session/config/workflow.rb +1 -373
- data/lib/eco/api/session/config.rb +30 -9
- data/lib/eco/api/usecases/base_case/model.rb +6 -6
- data/lib/eco/api/usecases/base_case.rb +1 -1
- data/lib/eco/api/usecases/cli.rb +1 -1
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +8 -9
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
- data/lib/eco/api/usecases/lib/base/env.rb +21 -23
- data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
- data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
- data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
- data/lib/eco/api/usecases/lib/files.rb +1 -0
- data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
- data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
- data/lib/eco/api/usecases/lib/locations.rb +7 -0
- data/lib/eco/api/usecases/lib/people/base.rb +20 -0
- data/lib/eco/api/usecases/lib/people.rb +6 -0
- data/lib/eco/api/usecases/lib.rb +2 -0
- data/lib/eco/api/usecases/ooze_cases.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +1 -0
- data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
- data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
- data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
- data/lib/eco/api/usecases/service/sftp.rb +7 -1
- data/lib/eco/api/usecases/use_case.rb +3 -2
- data/lib/eco/api/usecases/workflow.rb +5 -0
- data/lib/eco/api/usecases.rb +12 -5
- data/lib/eco/cli/scripting/args_helpers.rb +1 -9
- data/lib/eco/cli_default/options.rb +98 -68
- data/lib/eco/cli_default/workflow/end.rb +22 -0
- data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
- data/lib/eco/cli_default/workflow/load/data.rb +27 -0
- data/lib/eco/cli_default/workflow/load/input.rb +28 -0
- data/lib/eco/cli_default/workflow/load.rb +13 -0
- data/lib/eco/cli_default/workflow/options.rb +10 -0
- data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
- data/lib/eco/cli_default/workflow/report.rb +17 -0
- data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
- data/lib/eco/cli_default/workflow/usecases.rb +23 -0
- data/lib/eco/cli_default/workflow.rb +24 -180
- data/lib/eco/data/count_trace.rb +51 -0
- data/lib/eco/data/files/content.rb +39 -0
- data/lib/eco/data/files/directory.rb +78 -45
- data/lib/eco/data/files/encoding.rb +12 -21
- data/lib/eco/data/files/file_pattern.rb +15 -8
- data/lib/eco/data/files/folder.rb +196 -0
- data/lib/eco/data/files/relative_path.rb +54 -0
- data/lib/eco/data/files/timestamp.rb +18 -0
- data/lib/eco/data/files.rb +46 -5
- data/lib/eco/data/fuzzy_match.rb +1 -1
- data/lib/eco/data/hashes/array_diff.rb +11 -5
- data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
- data/lib/eco/data/mapper.rb +5 -1
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/delegation/delegating_missing.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
- data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
- data/lib/eco/language/klass/auto_loader.rb +129 -0
- data/lib/eco/language/klass/builder.rb +6 -6
- data/lib/eco/language/klass/const.rb +19 -0
- data/lib/eco/language/klass/helpers_built.rb +3 -1
- data/lib/eco/language/klass/hierarchy.rb +5 -1
- data/lib/eco/language/klass/naming.rb +5 -2
- data/lib/eco/language/klass/resolver.rb +21 -6
- data/lib/eco/language/klass/uid.rb +12 -0
- data/lib/eco/language/klass/when_inherited.rb +30 -6
- data/lib/eco/language/klass.rb +5 -2
- data/lib/eco/language/methods/access_modifier.rb +23 -0
- data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
- data/lib/eco/language/methods.rb +1 -0
- data/lib/eco/language/models/hierarchy.rb +41 -0
- data/lib/eco/language/models/workflow.rb +385 -0
- data/lib/eco/language/models.rb +2 -1
- data/lib/eco/version.rb +1 -1
- metadata +31 -7
- data/lib/eco/api/common/class_auto_loader.rb +0 -114
- data/lib/eco/api/common/class_helpers.rb +0 -9
- data/lib/eco/api/common/class_hierarchy.rb +0 -45
- data/lib/eco/data/files/helpers.rb +0 -152
- data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -1,73 +1,67 @@
|
|
1
|
-
module Eco
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class Environment
|
6
|
-
attr_reader :config, :session
|
7
|
-
attr_reader :file_manager, :logger
|
1
|
+
module Eco::API::Common::Session
|
2
|
+
class Environment
|
3
|
+
attr_reader :config, :session
|
4
|
+
attr_reader :file_manager, :logger
|
8
5
|
|
9
|
-
|
6
|
+
alias_method :fm, :file_manager
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
#@param init [Eco::API::Common::Session::Environment] object to ini the session environment
|
9
|
+
#@param session [Eco::API::Session, nil] the current session
|
10
|
+
def initialize(init = {}, session:)
|
11
|
+
init = init.conf if init.is_a?(Environment)
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
msg = "Expected object Eco::API::Session::Config or Environment. Given: #{init}"
|
14
|
+
raise msg unless init.is_a?(Eco::API::Session::Config)
|
18
15
|
|
19
|
-
|
20
|
-
|
16
|
+
invalid_session = session && !session.is_a?(Eco::API::Session)
|
17
|
+
raise "Expected an Eco::API::Session object. Given: #{session}" if invalid_session
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
@config = init
|
20
|
+
@session = session
|
21
|
+
@file_manager = Eco::API::Common::Session::FileManager.new(enviro: self)
|
22
|
+
@logger = Eco::API::Common::Session::Logger.new(enviro: self)
|
23
|
+
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
def mailer
|
26
|
+
return nil unless mailer?
|
27
|
+
@mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
def mailer?
|
31
|
+
config.mailer.configured?
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
def sftp
|
35
|
+
return nil unless sftp?
|
36
|
+
@sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
|
37
|
+
end
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
def sftp?
|
40
|
+
config.sftp.configured?
|
41
|
+
end
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
def s3uploader
|
44
|
+
return nil unless s3uploader?
|
45
|
+
@s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
|
46
|
+
end
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
def s3uploader?
|
49
|
+
config.s3storage.configured?
|
50
|
+
end
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
def api(version: nil)
|
53
|
+
config.api(logger, version: version)
|
54
|
+
end
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
def api?(version:)
|
57
|
+
config.apis.active_api.version_available?(version)
|
58
|
+
end
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
# Shortcut to logger.
|
61
|
+
def log(level, &block)
|
62
|
+
return unless logger.respond_to?(:level)
|
66
63
|
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
64
|
+
logger&.send(level, &block)
|
71
65
|
end
|
72
66
|
end
|
73
67
|
end
|
@@ -1,140 +1,137 @@
|
|
1
|
-
module Eco
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
file
|
105
|
-
end
|
106
|
-
|
107
|
-
def save(content, filename, modifier = :no_stamp, mode: :string)
|
108
|
-
file = filename_for(filename, modifier)
|
109
|
-
FileManager.create_directory(
|
110
|
-
FileManager.file_fullpath(file)
|
111
|
-
)
|
112
|
-
|
113
|
-
log(:debug) { "Writting to file '#{file}'" }
|
114
|
-
|
115
|
-
mode = mode == :binary ? 'wb' : 'w'
|
116
|
-
File.open(file, mode) { |fd| fd << content }
|
117
|
-
file
|
118
|
-
end
|
119
|
-
|
120
|
-
# if the file does not exist, it creates it
|
121
|
-
def append(content, filename, mode: :string)
|
122
|
-
file = dir.file(filename)
|
123
|
-
|
124
|
-
log(:debug) { "Appending to file '#{file}'" }
|
125
|
-
|
126
|
-
mode = mode == :binary ? 'ab' : 'a'
|
127
|
-
File.open(file, mode) { |fd| fd << "#{content}\n" }
|
128
|
-
file
|
129
|
-
end
|
130
|
-
|
131
|
-
def filename_for(filename, modifier = :no_stamp)
|
132
|
-
file = dir.file(filename)
|
133
|
-
file = FileManager.timestamp_file(file) if modifier == :timestamp
|
134
|
-
file
|
135
|
-
end
|
1
|
+
module Eco::API::Common::Session
|
2
|
+
class FileManager
|
3
|
+
include Eco::Data::Files
|
4
|
+
include Eco::Language::AuxiliarLogger
|
5
|
+
|
6
|
+
attr_reader :dir, :dir_path
|
7
|
+
attr_accessor :timestamp_pattern
|
8
|
+
|
9
|
+
def initialize(init = {}, enviro: nil)
|
10
|
+
@enviro = enviro
|
11
|
+
init = @enviro.config if @enviro && init.empty?
|
12
|
+
|
13
|
+
@timestamp_pattern = init.files.timestamp_pattern
|
14
|
+
@timestamp_pattern ||= Eco::Data::Files::Timestamp::DEFAULT_TIMESTAMP
|
15
|
+
self.dir_path = init.working_directory || Dir.pwd
|
16
|
+
end
|
17
|
+
|
18
|
+
def dir_path=(value)
|
19
|
+
@dir = Eco::Data::Files::Directory.new(value)
|
20
|
+
dir.create(exception: true)
|
21
|
+
|
22
|
+
@dir_path = dir.full_path
|
23
|
+
rescue StandardError => err
|
24
|
+
log(:error) {
|
25
|
+
"could not create or make any sense of directory '#{value}': #{err}"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger
|
30
|
+
return @enviro.logger if @enviro
|
31
|
+
super if defined?(super)
|
32
|
+
end
|
33
|
+
|
34
|
+
##### FILE #####
|
35
|
+
|
36
|
+
# @return [String] resolved filename path (relative or absolute)
|
37
|
+
def file(filename, should_exist: false)
|
38
|
+
dir.file(filename, should_exist: should_exist)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String] newest file by last modified date.
|
42
|
+
def newest(filename)
|
43
|
+
dir.newest_file(file: filename)
|
44
|
+
end
|
45
|
+
|
46
|
+
def file_content(filename, mode: nil)
|
47
|
+
file = dir.file(filename, should_exist: true)
|
48
|
+
|
49
|
+
unless file
|
50
|
+
log(:error) {
|
51
|
+
"Can't read from file '#{filename}' because it does not exist."
|
52
|
+
}
|
53
|
+
return nil
|
54
|
+
end
|
55
|
+
|
56
|
+
log(:debug) { "Reading from file '#{file}'" }
|
57
|
+
mode ? File.read(file, mode: mode) : File.read(file)
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_json(filename)
|
61
|
+
file = dir.file(filename, should_exist: true)
|
62
|
+
|
63
|
+
unless file
|
64
|
+
log(:error) {
|
65
|
+
"Can't read from file '#{filename}' because it does not exist."
|
66
|
+
}
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
|
70
|
+
fd = File.open(file)
|
71
|
+
JSON.load fd # rubocop:disable Security/JSONLoad
|
72
|
+
rescue JSON::ParserError => e
|
73
|
+
pp "Parsing error on file #{file}"
|
74
|
+
raise e
|
75
|
+
ensure
|
76
|
+
fd&.close
|
77
|
+
end
|
78
|
+
|
79
|
+
def touch(filename, modifier = :no_stamp, mode: :string)
|
80
|
+
save('', filename, modifier, mode: mode)
|
81
|
+
end
|
82
|
+
|
83
|
+
def save_json(data, filename, modifier = :no_stamp)
|
84
|
+
return save(data.to_json, filename, modifier) unless data.is_a?(Array)
|
85
|
+
|
86
|
+
file = filename_for(filename, modifier)
|
87
|
+
FileUtils.mkdir_p(File.dirname(file))
|
88
|
+
|
89
|
+
log(:debug) { "Writting to file '#{file}'" }
|
90
|
+
|
91
|
+
mode = mode == :binary ? 'wb' : 'w'
|
92
|
+
|
93
|
+
File.open(file, mode) do |fd|
|
94
|
+
first = true
|
95
|
+
|
96
|
+
fd << '['
|
97
|
+
data.each do |elem|
|
98
|
+
fd << "," unless first
|
99
|
+
first = false
|
100
|
+
|
101
|
+
fd << elem.to_json
|
136
102
|
end
|
103
|
+
fd << ']'
|
137
104
|
end
|
105
|
+
|
106
|
+
file
|
107
|
+
end
|
108
|
+
|
109
|
+
def save(content, filename, modifier = :no_stamp, mode: :string)
|
110
|
+
file = filename_for(filename, modifier)
|
111
|
+
FileUtils.mkdir_p(File.dirname(file))
|
112
|
+
|
113
|
+
log(:debug) { "Writting to file '#{file}'" }
|
114
|
+
|
115
|
+
mode = mode == :binary ? 'wb' : 'w'
|
116
|
+
File.open(file, mode) { |fd| fd << content }
|
117
|
+
file
|
118
|
+
end
|
119
|
+
|
120
|
+
# if the file does not exist, it creates it
|
121
|
+
def append(content, filename, mode: :string)
|
122
|
+
file = dir.file(filename)
|
123
|
+
|
124
|
+
log(:debug) { "Appending to file '#{file}'" }
|
125
|
+
|
126
|
+
mode = mode == :binary ? 'ab' : 'a'
|
127
|
+
File.open(file, mode) { |fd| fd << "#{content}\n" }
|
128
|
+
file
|
129
|
+
end
|
130
|
+
|
131
|
+
def filename_for(filename, modifier = :no_stamp)
|
132
|
+
file = dir.file(filename)
|
133
|
+
file = FileManager.timestamp_file(file) if modifier == :timestamp
|
134
|
+
file
|
138
135
|
end
|
139
136
|
end
|
140
137
|
end
|
@@ -1,38 +1,31 @@
|
|
1
|
-
module Eco
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module PromptUser
|
7
|
-
# Prompts user for input with option for default on timeout.
|
8
|
-
def prompt_user(question, default:, explanation: '', timeout: nil)
|
9
|
-
require 'timeout'
|
10
|
-
response =
|
11
|
-
if config.run_mode_remote?
|
12
|
-
default
|
13
|
-
else
|
14
|
-
puts explanation
|
15
|
-
print "#{question} "
|
1
|
+
module Eco::API::Common::Session::Helpers
|
2
|
+
module PromptUser
|
3
|
+
# Prompts user for input with option for default on timeout.
|
4
|
+
def prompt_user(question, default:, explanation: '', timeout: nil)
|
5
|
+
require 'timeout'
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
default
|
24
|
-
end
|
25
|
-
else
|
26
|
-
STDIN.gets.chop
|
27
|
-
end
|
28
|
-
end
|
29
|
-
return response unless block_given?
|
7
|
+
response =
|
8
|
+
if config.run_mode_remote?
|
9
|
+
default
|
10
|
+
else
|
11
|
+
puts explanation
|
12
|
+
print "#{question} "
|
30
13
|
|
31
|
-
|
14
|
+
if timeout
|
15
|
+
begin
|
16
|
+
Timeout.timeout(timeout) { $stdin.gets.chop }
|
17
|
+
rescue Timeout::Error
|
18
|
+
print default
|
19
|
+
puts "\n"
|
20
|
+
default
|
32
21
|
end
|
22
|
+
else
|
23
|
+
$stdin.gets.chop
|
33
24
|
end
|
34
25
|
end
|
35
|
-
|
26
|
+
return response unless block_given?
|
27
|
+
|
28
|
+
yield(response)
|
36
29
|
end
|
37
30
|
end
|
38
31
|
end
|
@@ -1,21 +1,16 @@
|
|
1
|
-
require_relative 'helpers/prompt_user'
|
2
1
|
|
3
|
-
module Eco
|
4
|
-
module
|
5
|
-
|
6
|
-
module Session
|
7
|
-
module Helpers
|
8
|
-
class << self
|
9
|
-
def included(base)
|
10
|
-
base.send(:include, InstanceMethods)
|
11
|
-
end
|
12
|
-
end
|
2
|
+
module Eco::API::Common::Session
|
3
|
+
module Helpers
|
4
|
+
require_relative 'helpers/prompt_user'
|
13
5
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
6
|
+
class << self
|
7
|
+
def included(base)
|
8
|
+
base.send(:include, InstanceMethods)
|
18
9
|
end
|
19
10
|
end
|
11
|
+
|
12
|
+
module InstanceMethods
|
13
|
+
include Helpers::PromptUser
|
14
|
+
end
|
20
15
|
end
|
21
16
|
end
|
@@ -1,101 +1,94 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
where(start_time, end_time) do |cond|
|
30
|
-
to_levels(level).map do |lev|
|
31
|
-
self.level(lev).reject(&cond)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def logs(level: nil, start_time: nil, end_time: nil)
|
38
|
-
where(start_time, end_time) do |cond|
|
39
|
-
to_levels(level).map do |lev|
|
40
|
-
self.level(lev).select(&cond)
|
41
|
-
end.flatten
|
42
|
-
end.sort
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def where(start_time, end_time)
|
48
|
-
tstart = to_datetime(start_time)
|
49
|
-
tend = to_datetime(end_time)
|
50
|
-
condition = proc do |log|
|
51
|
-
next true unless tstart || tend
|
52
|
-
|
53
|
-
log.after?(tstart) && log.before?(tend)
|
54
|
-
end
|
55
|
-
|
56
|
-
yield(condition)
|
57
|
-
end
|
58
|
-
|
59
|
-
def to_datetime(value)
|
60
|
-
return unless value
|
61
|
-
|
62
|
-
Time.parse(value)
|
63
|
-
end
|
64
|
-
|
65
|
-
def to_levels(value)
|
66
|
-
levels = [value].flatten.map {|v| to_level(v)}.compact
|
67
|
-
return levels unless levels.empty?
|
68
|
-
|
69
|
-
valid_levels
|
70
|
-
end
|
71
|
-
|
72
|
-
def to_level(value)
|
73
|
-
nil_or_upcase(value).tap do |out|
|
74
|
-
valid_level!(out)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def valid_level!(str)
|
79
|
-
return true unless str
|
80
|
-
return true if valid_levels.any? {|lev| str == lev}
|
81
|
-
|
82
|
-
msg = "Unknown level #{str}. Should be one of #{LEVELS}"
|
83
|
-
raise ArgumentError, msg
|
84
|
-
end
|
85
|
-
|
86
|
-
def nil_or_upcase(value)
|
87
|
-
value = value.to_s.upcase if value
|
88
|
-
return yield(value) if block_given?
|
89
|
-
|
90
|
-
value
|
91
|
-
end
|
92
|
-
|
93
|
-
def valid_levels
|
94
|
-
@valid_levels ||= self.class::LEVELS | self.class::CHANNELS
|
95
|
-
end
|
96
|
-
end
|
1
|
+
class Eco::API::Common::Session::Logger
|
2
|
+
class Cache
|
3
|
+
LEVELS = %w[UNKNOWN FATAL ERROR WARN INFO DEBUG].freeze
|
4
|
+
CHANNELS = Eco::API::Common::Session::Logger::CHANNELS.
|
5
|
+
map(&:to_s).map(&:upcase).freeze
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
reset
|
9
|
+
end
|
10
|
+
|
11
|
+
def level(level)
|
12
|
+
cache[to_level(level)] ||= []
|
13
|
+
end
|
14
|
+
|
15
|
+
def add(level, datetime, message, formatted)
|
16
|
+
Eco::API::Common::Session::Logger::Log.new(level, datetime, message, formatted).tap do |log|
|
17
|
+
self.level(level).push(log)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def cache
|
22
|
+
@cache ||= {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset(level: nil, start_time: nil, end_time: nil)
|
26
|
+
where(start_time, end_time) do |cond|
|
27
|
+
to_levels(level).map do |lev|
|
28
|
+
self.level(lev).reject(&cond)
|
97
29
|
end
|
98
30
|
end
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def logs(level: nil, start_time: nil, end_time: nil)
|
35
|
+
where(start_time, end_time) do |cond|
|
36
|
+
to_levels(level).map do |lev|
|
37
|
+
self.level(lev).select(&cond)
|
38
|
+
end.flatten
|
39
|
+
end.sort
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def where(start_time, end_time)
|
45
|
+
tstart = to_datetime(start_time)
|
46
|
+
tend = to_datetime(end_time)
|
47
|
+
condition = proc do |log|
|
48
|
+
next true unless tstart || tend
|
49
|
+
|
50
|
+
log.after?(tstart) && log.before?(tend)
|
51
|
+
end
|
52
|
+
|
53
|
+
yield(condition)
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_datetime(value)
|
57
|
+
return unless value
|
58
|
+
|
59
|
+
Time.parse(value)
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_levels(value)
|
63
|
+
levels = [value].flatten.map {|v| to_level(v)}.compact
|
64
|
+
return levels unless levels.empty?
|
65
|
+
|
66
|
+
valid_levels
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_level(value)
|
70
|
+
nil_or_upcase(value).tap do |out|
|
71
|
+
valid_level!(out)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def valid_level!(str)
|
76
|
+
return true unless str
|
77
|
+
return true if valid_levels.any? {|lev| str == lev}
|
78
|
+
|
79
|
+
msg = "Unknown level #{str}. Should be one of #{LEVELS}"
|
80
|
+
raise ArgumentError, msg
|
81
|
+
end
|
82
|
+
|
83
|
+
def nil_or_upcase(value)
|
84
|
+
value = value.to_s.upcase if value
|
85
|
+
return yield(value) if block_given?
|
86
|
+
|
87
|
+
value
|
88
|
+
end
|
89
|
+
|
90
|
+
def valid_levels
|
91
|
+
@valid_levels ||= self.class::LEVELS | self.class::CHANNELS
|
99
92
|
end
|
100
93
|
end
|
101
94
|
end
|