eco-rake 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -4
- data/lib/eco-rake/base/method_helpers.rb +7 -3
- data/lib/eco-rake/base/symbol_resolver.rb +7 -4
- data/lib/eco-rake/base.rb +1 -1
- data/lib/eco-rake/default/const.rb +5 -3
- data/lib/eco-rake/default.rb +1 -1
- data/lib/eco-rake/lib/files/sftp.rb +10 -7
- data/lib/eco-rake/lib/people/sync_launch.rb +3 -1
- data/lib/eco-rake/lib/people/sync_rely.rb +9 -4
- data/lib/eco-rake/lib/task/runner_rely.rb +2 -2
- data/lib/eco-rake/options/default_lookup.rb +19 -3
- data/lib/eco-rake/options/forwarding.rb +1 -1
- data/lib/eco-rake/options/library.rb +1 -1
- data/lib/eco-rake/options/parental.rb +3 -1
- data/lib/eco-rake/options.rb +1 -1
- data/lib/eco-rake/patches/exception.rb +2 -0
- data/lib/eco-rake/rake_task.rb +1 -1
- data/lib/eco-rake/shell/command.rb +3 -0
- data/lib/eco-rake/shell/gpg.rb +1 -1
- data/lib/eco-rake/shell.rb +1 -1
- data/lib/eco-rake/utils/mailer.rb +1 -36
- data/lib/eco-rake/utils/mailing.rb +5 -5
- data/lib/eco-rake/utils.rb +1 -1
- data/lib/eco-rake/version.rb +1 -1
- data/lib/eco-rake.rb +2 -2
- metadata +2 -3
- data/lib/eco-rake/tasks.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb719b1d4007c97f0d94b045c9fdb61573feec430243333a324e078445e519d9
|
4
|
+
data.tar.gz: 1349f5045662ea64d24a8a60ee4d972b25c9086698eb1711896937a729091e2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0969c6c5dd289cd62aad753ae0349b4fb7c00fd412c77e9e0c49da6a79def74dd06fed98ff5d2f48077defbaaccbde645a50f83e92fde542d85958b89d093186'
|
7
|
+
data.tar.gz: b1d8a5183b981a97e7a1f1c1ec3c42fd65c1d0f83e0bbe31cc76db7245a702ff1eb3703ba49d0ff49e89d75a079e16aeaafc21b7289a03df27ae3fd7998cdce0
|
data/CHANGELOG.md
CHANGED
@@ -2,18 +2,27 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [0.2.
|
5
|
+
## [0.2.7] - 2024-12-16
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
9
|
-
- `EcoRake::Lib::People::SyncLaunch`
|
10
|
-
-
|
11
|
-
- Which will use all the files with matching pattern within.
|
9
|
+
- `EcoRake::Lib::People::SyncLaunch`
|
10
|
+
- New constant `TARGET_NAMESPACE`: to build up the target task based on a different namespace (i.e. not nested).
|
12
11
|
|
13
12
|
### Fixed
|
14
13
|
|
15
14
|
### Changed
|
16
15
|
|
16
|
+
- code tidy up
|
17
|
+
|
18
|
+
## [0.2.6] - 2024-12-09
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
- `EcoRake::Lib::People::SyncLaunch` new constant `join_files`
|
23
|
+
- To specify the integration to use the target folder in raw
|
24
|
+
- Which will use all the files with matching pattern within.
|
25
|
+
|
17
26
|
## [0.2.5] - 2024-10-01
|
18
27
|
|
19
28
|
### Added
|
@@ -7,6 +7,7 @@ class EcoRake
|
|
7
7
|
def safe_call(meth, *args, **kargs, &block)
|
8
8
|
msg = "Expecting Method or Proc. Given: #{meth.class}"
|
9
9
|
raise ArgumentError, msg unless [Method, Proc].any? {|c| meth.is_a?(c)}
|
10
|
+
|
10
11
|
aux_curry(meth, :safe).call(*args, **kargs, &block)
|
11
12
|
end
|
12
13
|
|
@@ -17,7 +18,7 @@ class EcoRake
|
|
17
18
|
# - `:safe` -> it sets to `nil` the missing required arguments and does a call.
|
18
19
|
# - `:return` -> it returns `nil` but doesn't call.
|
19
20
|
# @return [Lambda, NilClass, Result]
|
20
|
-
def aux_curry(meth, on_missing = :curry)
|
21
|
+
def aux_curry(meth, on_missing = :curry) # rubocop:disable Metrics/AbcSize
|
21
22
|
lambda do |*args, **kargs, &block|
|
22
23
|
params = meth.parameters
|
23
24
|
kparams = params.select { |type, _| (type == :keyreq) || (type == :key) }
|
@@ -25,7 +26,7 @@ class EcoRake
|
|
25
26
|
|
26
27
|
kreq_miss = kparams.select { |type, _| type == :keyreq }.map(&:last) - kargs.keys
|
27
28
|
req_miss = aparams.select { |type, _| type == :req }.count - args.count
|
28
|
-
req_miss = req_miss
|
29
|
+
req_miss = [req_miss, 0].max
|
29
30
|
ready = kreq_miss.empty? && req_miss.zero?
|
30
31
|
|
31
32
|
if on_missing == :safe
|
@@ -34,6 +35,7 @@ class EcoRake
|
|
34
35
|
kextras = kargs.keys - kparams.map(&:last)
|
35
36
|
kextras.each { |name| kargs.delete(name) } unless keyrest
|
36
37
|
args = args[0..(aparams.count-1)] unless argrest || args.count <= aparams.count
|
38
|
+
|
37
39
|
unless ready
|
38
40
|
kreq_miss.each { |name| kargs[name] = nil }
|
39
41
|
ary_nil = Array.new(req_miss, nil)
|
@@ -41,8 +43,10 @@ class EcoRake
|
|
41
43
|
ready = true
|
42
44
|
end
|
43
45
|
end
|
46
|
+
|
44
47
|
return meth.call(*args, **kargs, &block) if ready || on_missing == :call
|
45
|
-
return
|
48
|
+
return if on_missing == :return
|
49
|
+
|
46
50
|
# (default) on_missing == :curry
|
47
51
|
lambda do |*oth, **koth, &blk|
|
48
52
|
curried = aux_curry(meth, on_missing)
|
@@ -48,7 +48,8 @@ class EcoRake
|
|
48
48
|
# @param sym [Symbol, String] that we try to resolve to a value of a constant.
|
49
49
|
# @return [Value, NilClass] `nil` when unresolved, the value of the constant otherwise.
|
50
50
|
def resolve_const(sym, source: self)
|
51
|
-
return
|
51
|
+
return unless sym.is_a?(Symbol) || sym.is_a?(String)
|
52
|
+
|
52
53
|
sym = constant_name(sym)
|
53
54
|
value = nil
|
54
55
|
value ||= safe_const_get(sym, klass: source)
|
@@ -70,11 +71,13 @@ class EcoRake
|
|
70
71
|
# @param sym [Symbol, String] that we try to resolve to a method.
|
71
72
|
# @return [Method, NilClass] `nil` when unresolved, the `method` otherwise.
|
72
73
|
def resolve_method(sym, source: self)
|
73
|
-
return
|
74
|
+
return unless sym.is_a?(Symbol) || sym.is_a?(String)
|
75
|
+
|
74
76
|
meth = source.method(sym) if source.respond_to?(sym, true)
|
75
77
|
return meth if meth
|
76
|
-
return
|
77
|
-
return
|
78
|
+
return if source.is_a?(Class)
|
79
|
+
return unless source.class.respond_to?(sym, true)
|
80
|
+
|
78
81
|
source.class.method(sym)
|
79
82
|
end
|
80
83
|
end
|
data/lib/eco-rake/base.rb
CHANGED
@@ -3,7 +3,7 @@ class EcoRake
|
|
3
3
|
module Const
|
4
4
|
class << self
|
5
5
|
def included(base)
|
6
|
-
super
|
6
|
+
super
|
7
7
|
base.extend EcoRake::Base::SymbolResolver
|
8
8
|
base.extend ClassMethods
|
9
9
|
end
|
@@ -27,10 +27,12 @@ class EcoRake
|
|
27
27
|
end
|
28
28
|
|
29
29
|
define_singleton_method attr do
|
30
|
-
msg = "Missing const '#{attr.to_s.upcase}' in #{self}"
|
31
30
|
value = resolve_const(attr)
|
32
|
-
value = default
|
31
|
+
value = default if value.nil? && default != :not_used
|
32
|
+
|
33
|
+
msg = "Missing const '#{attr.to_s.upcase}' in #{self}"
|
33
34
|
raise NameError, msg if value.nil? && required
|
35
|
+
|
34
36
|
yield(value) if block_given?
|
35
37
|
value
|
36
38
|
end
|
data/lib/eco-rake/default.rb
CHANGED
@@ -3,12 +3,12 @@ class EcoRake
|
|
3
3
|
module Files
|
4
4
|
class Sftp < EcoRake::Lib::BaseTask
|
5
5
|
FORWARD_RULES = {
|
6
|
-
enviro:
|
7
|
-
folder:
|
8
|
-
list:
|
9
|
-
get_last:
|
10
|
-
get:
|
11
|
-
archive:
|
6
|
+
enviro: ->(enviro) { "-#{enviro}" },
|
7
|
+
folder: ->(folder) { "-local-folder #{folder}"},
|
8
|
+
list: '-list',
|
9
|
+
get_last: '-get-last',
|
10
|
+
get: '-get',
|
11
|
+
archive: '-archive',
|
12
12
|
file_pattern: ->(str) { "-file-pattern-const #{str}"},
|
13
13
|
remote_subfolder: ->(sub) { "-remote-subfolder #{sub}"}
|
14
14
|
}.freeze
|
@@ -38,7 +38,10 @@ class EcoRake
|
|
38
38
|
def sftp_command
|
39
39
|
cmd = [base_command]
|
40
40
|
cmd << forward_option(:folder)
|
41
|
-
|
41
|
+
|
42
|
+
forwarded = forward_options(:list, :get_last, :get, :archive).compact.first
|
43
|
+
cmd << (forwarded || '-list')
|
44
|
+
|
42
45
|
cmd.push(*forward_options(:remote_subfolder, :file_pattern))
|
43
46
|
cmd << '-no-people'
|
44
47
|
cmd = yield(cmd) if block_given?
|
@@ -31,6 +31,7 @@ class EcoRake
|
|
31
31
|
def task(*_args)
|
32
32
|
return missing_files_notify unless latest_file
|
33
33
|
return process_deltas if delta?
|
34
|
+
|
34
35
|
process_full_file if full? || delta_last?
|
35
36
|
end
|
36
37
|
|
@@ -53,8 +54,9 @@ class EcoRake
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def missing_files_notify
|
56
|
-
msg =
|
57
|
+
msg = 'Missing files to be processed'
|
57
58
|
puts msg
|
59
|
+
|
58
60
|
exit 1 if options[:simulate]
|
59
61
|
exit 1 if options[:no_email]
|
60
62
|
exit 1 unless (inbox = mail_to)
|
@@ -17,6 +17,7 @@ class EcoRake
|
|
17
17
|
option_forwarding(**FORWARD_RULES)
|
18
18
|
|
19
19
|
attr_const :target_task
|
20
|
+
attr_const :target_namespace
|
20
21
|
|
21
22
|
def task(*_args)
|
22
23
|
sh_continue rake_sync_command
|
@@ -40,10 +41,14 @@ class EcoRake
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def namespaced_task(task_name = target_task)
|
43
|
-
ns
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
ns = target_namespace
|
45
|
+
unless ns
|
46
|
+
ns = self.class.namespace || ''
|
47
|
+
ns_with_enviro = ns.split(':').any? {|s| s == options[:enviro]}
|
48
|
+
ns = [ns, options[:enviro]].compact.join(':') unless ns_with_enviro
|
49
|
+
end
|
50
|
+
|
51
|
+
[ns, task_name || self.class.task].compact.join(':')
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -3,7 +3,7 @@ class EcoRake
|
|
3
3
|
module DefaultLookup
|
4
4
|
class << self
|
5
5
|
def included(base)
|
6
|
-
super
|
6
|
+
super
|
7
7
|
base.extend EcoRake::Base::MethodHelpers
|
8
8
|
base.extend ClassMethods
|
9
9
|
end
|
@@ -14,13 +14,29 @@ class EcoRake
|
|
14
14
|
# 1. default can be re-configured via callback or constant
|
15
15
|
# [ @see RakeCommander::Options::option ]
|
16
16
|
def option(*args, default_lookup: :not_used, **kargs, &block)
|
17
|
-
|
17
|
+
unless default_lookup == :not_used
|
18
|
+
kargs.merge!(
|
19
|
+
default: symbol_resolver(
|
20
|
+
default_lookup,
|
21
|
+
as: %i[method const]
|
22
|
+
)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
18
26
|
super(*args, **kargs, &block)
|
19
27
|
end
|
20
28
|
|
21
29
|
# [ @see RakeCommander::Options::option_reopen ]
|
22
30
|
def option_reopen(*args, default_lookup: :not_used, **kargs, &block)
|
23
|
-
|
31
|
+
unless default_lookup == :not_used
|
32
|
+
kargs.merge!(
|
33
|
+
default: symbol_resolver(
|
34
|
+
default_lookup,
|
35
|
+
as: %i[method const]
|
36
|
+
)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
24
40
|
super(*args, **kargs, &block)
|
25
41
|
end
|
26
42
|
end
|
@@ -3,7 +3,7 @@ class EcoRake
|
|
3
3
|
module Parental
|
4
4
|
class << self
|
5
5
|
def included(base)
|
6
|
-
super
|
6
|
+
super
|
7
7
|
base.extend ClassMethods
|
8
8
|
end
|
9
9
|
end
|
@@ -21,6 +21,7 @@ class EcoRake
|
|
21
21
|
def delete_from_options(opt)
|
22
22
|
super.tap do |out|
|
23
23
|
next unless opt.respond_to?(:parent=)
|
24
|
+
|
24
25
|
out.parent = nil if opt == out
|
25
26
|
end
|
26
27
|
end
|
@@ -28,6 +29,7 @@ class EcoRake
|
|
28
29
|
def replace_in_options(ref, opt, **kargs)
|
29
30
|
super.tap do |out|
|
30
31
|
next unless opt.respond_to?(:parent=)
|
32
|
+
|
31
33
|
ref.parent = nil if opt == out
|
32
34
|
end
|
33
35
|
end
|
data/lib/eco-rake/options.rb
CHANGED
data/lib/eco-rake/rake_task.rb
CHANGED
@@ -32,6 +32,7 @@ class EcoRake
|
|
32
32
|
def sh_chain(cmds, continue: false, &block)
|
33
33
|
cmds.each do |cmd|
|
34
34
|
next sh(cmd, &block) unless continue
|
35
|
+
|
35
36
|
ch_continue(cmd, &block)
|
36
37
|
end
|
37
38
|
end
|
@@ -60,10 +61,12 @@ class EcoRake
|
|
60
61
|
def sh_default_block(comm)
|
61
62
|
proc do |ok, res|
|
62
63
|
yield(ok, res) if block_given?
|
64
|
+
|
63
65
|
unless ok
|
64
66
|
msg = "Command failed (status = #{res.exitstatus})"
|
65
67
|
puts "#{msg}\n • #{comm}"
|
66
68
|
end
|
69
|
+
|
67
70
|
res.exitstatus
|
68
71
|
end
|
69
72
|
end
|
data/lib/eco-rake/shell/gpg.rb
CHANGED
@@ -4,7 +4,7 @@ class EcoRake
|
|
4
4
|
include EcoRake::Shell::Command
|
5
5
|
include EcoRake::Shell::Files
|
6
6
|
|
7
|
-
GPG_VERSION_REGEX = /^gpg.*?gnupg.*?(?<maj>\d+)\.(?<min>\d+)\./i
|
7
|
+
GPG_VERSION_REGEX = /^gpg.*?gnupg.*?(?<maj>\d+)\.(?<min>\d+)\./i
|
8
8
|
|
9
9
|
# @note
|
10
10
|
# 1. The ENV var `GPG_KEY` specifies the `passphrase` to be able to use the
|
data/lib/eco-rake/shell.rb
CHANGED
@@ -14,46 +14,11 @@ class EcoRake
|
|
14
14
|
DEFAULT_PROVIDER = :sendgrid
|
15
15
|
|
16
16
|
attr_reader :provider
|
17
|
+
|
17
18
|
def initialize(provider: DEFAULT_PROVIDER)
|
18
19
|
@provider = provider || DEFAULT_PROVIDER
|
19
20
|
end
|
20
21
|
|
21
|
-
# Sends an email
|
22
|
-
# @param to [String] destination email address
|
23
|
-
# @param subject [String] subject of the email
|
24
|
-
# @param body [String] `html` or plain text message
|
25
|
-
# @param from [String] the email address this is send **from**
|
26
|
-
def mail(to:, subject:, body:, from: nil, cc: nil, bcc: nil)
|
27
|
-
unless configured?
|
28
|
-
puts "Mailer: You are missing configuration parameters. Review your .env file"
|
29
|
-
return false
|
30
|
-
end
|
31
|
-
|
32
|
-
ses.send_email(
|
33
|
-
destination: fetch_to(to: to, cc: cc, bcc: bcc),
|
34
|
-
source: fetch_from(from),
|
35
|
-
message: {
|
36
|
-
subject: {
|
37
|
-
charset: "UTF-8",
|
38
|
-
data: subject
|
39
|
-
},
|
40
|
-
body: {
|
41
|
-
# NOTEL: `html:` will let you send html instead
|
42
|
-
# you can use both at once if you like
|
43
|
-
text: {
|
44
|
-
charset: "UTF-8",
|
45
|
-
data: body
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
).tap do |response|
|
50
|
-
puts "Sent email to #{to} (MessageId: #{response.message_id})"
|
51
|
-
end
|
52
|
-
rescue StandardError => err
|
53
|
-
msg = "The mailer generated an exception:\n"
|
54
|
-
msg << err.patch_full_message(trace_count: 15)
|
55
|
-
puts msg
|
56
|
-
end
|
57
22
|
# Sends an email
|
58
23
|
# @param to [String] destination email address
|
59
24
|
# @param subject [String] subject of the email
|
@@ -7,22 +7,22 @@ class EcoRake
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def email(subject:, body:, to:, enviro: nil)
|
10
|
-
has_enviro = enviro && subject
|
10
|
+
has_enviro = enviro && subject&.downcase&.include?(enviro.downcase)
|
11
11
|
subject = "#{enviro.upcase} - #{subject}" if enviro && !has_enviro
|
12
|
-
mailer.mail(
|
12
|
+
mailer.mail(
|
13
13
|
to: to,
|
14
14
|
subject: subject,
|
15
15
|
body: body
|
16
|
-
|
16
|
+
)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Helper to notify that there are no files to be processed
|
20
20
|
def email_missing_files(enviro:, to:)
|
21
|
-
email(
|
21
|
+
email(
|
22
22
|
to: to,
|
23
23
|
subject: "#{enviro.upcase} (No files to be processed)",
|
24
24
|
body: 'No files found to be processed. Aborting...'
|
25
|
-
|
25
|
+
)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/eco-rake/utils.rb
CHANGED
data/lib/eco-rake/version.rb
CHANGED
data/lib/eco-rake.rb
CHANGED
@@ -3,7 +3,7 @@ require 'dotenv'
|
|
3
3
|
require 'dotenv/load'
|
4
4
|
|
5
5
|
class EcoRake < RakeCommander
|
6
|
-
autoload_namespace_ignore
|
6
|
+
# autoload_namespace_ignore 'EcoRake::Tasks'
|
7
7
|
|
8
8
|
require_relative 'eco-rake/version'
|
9
9
|
require_relative 'eco-rake/patches'
|
@@ -11,7 +11,7 @@ class EcoRake < RakeCommander
|
|
11
11
|
include EcoRake::Base
|
12
12
|
end
|
13
13
|
|
14
|
-
RakeCommander::Patcher.debug = ENV['COMMANDER_DEBUG'] ==
|
14
|
+
RakeCommander::Patcher.debug = ENV['COMMANDER_DEBUG'] == 'true'
|
15
15
|
|
16
16
|
require_relative 'eco-rake/lib'
|
17
17
|
require_relative 'eco-rake/custom'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura Samper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -245,7 +245,6 @@ files:
|
|
245
245
|
- lib/eco-rake/shell/eco_helpers.rb
|
246
246
|
- lib/eco-rake/shell/files.rb
|
247
247
|
- lib/eco-rake/shell/gpg.rb
|
248
|
-
- lib/eco-rake/tasks.rb
|
249
248
|
- lib/eco-rake/utils.rb
|
250
249
|
- lib/eco-rake/utils/mailer.rb
|
251
250
|
- lib/eco-rake/utils/mailer/aws_provider.rb
|
data/lib/eco-rake/tasks.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require_relative 'tasks/decrypt'
|
2
|
-
require_relative 'tasks/feed'
|
3
|
-
require_relative 'tasks/hris'
|
4
|
-
require_relative 'tasks/sftp'
|
5
|
-
|
6
|
-
# Offers a set of preconfigured tasks to inherit from
|
7
|
-
# @note that these samples themselves do not get autoloaded,
|
8
|
-
# although their children do.
|
9
|
-
class EcoRake
|
10
|
-
module Tasks
|
11
|
-
end
|
12
|
-
end
|