eco-rake 0.2.6 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6f834edf2918e4ff4e45cfcf538da2e59b632fad4222a3b996f5ab00c60fb25
4
- data.tar.gz: 1f0a90c3242171b560b6adb848e50fc58cd569e61e915e7e9363e6c50c4c6266
3
+ metadata.gz: eb719b1d4007c97f0d94b045c9fdb61573feec430243333a324e078445e519d9
4
+ data.tar.gz: 1349f5045662ea64d24a8a60ee4d972b25c9086698eb1711896937a729091e2b
5
5
  SHA512:
6
- metadata.gz: b619ed8b4ebdf32cb30fdef61f5821d821c1338464e3cfe5d2331df930f00582c0c008c1fe3dac53744b328e4d126a8609f87c71d647889028215f9b709e0895
7
- data.tar.gz: c90b0316f090eec3f5ed131a0bfd808e75ca190f38c8f5f447524161de88c43f39aafe0d9db91a6882c4d7bd70a62ece823a3fde56cdfdc71062eee178d934a6
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.6] - 2024-12-09
5
+ ## [0.2.7] - 2024-12-16
6
6
 
7
7
  ### Added
8
8
 
9
- - `EcoRake::Lib::People::SyncLaunch` new constant `join_files`
10
- - To specify the integration to use the target folder in raw
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 >= 0 ? req_miss : 0
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 nil if on_missing == :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 nil unless sym.is_a?(Symbol) || sym.is_a?(String)
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 nil unless sym.is_a?(Symbol) || sym.is_a?(String)
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 nil if source.is_a?(Class)
77
- return nil unless source.class.respond_to?(sym, true)
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
@@ -11,7 +11,7 @@ class EcoRake
11
11
  module Base
12
12
  class << self
13
13
  def included(base)
14
- super(base)
14
+ super
15
15
  base.autoloads_children_of RakeCommander
16
16
  base.extend ClassMethods
17
17
  base.send :include, RakeTask
@@ -3,7 +3,7 @@ class EcoRake
3
3
  module Const
4
4
  class << self
5
5
  def included(base)
6
- super(base)
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 if value.nil? && default != :not_used
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
@@ -4,7 +4,7 @@ class EcoRake
4
4
  module Default
5
5
  class << self
6
6
  def included(base)
7
- super(base)
7
+ super
8
8
  base.send :include, Const
9
9
  end
10
10
  end
@@ -3,12 +3,12 @@ class EcoRake
3
3
  module Files
4
4
  class Sftp < EcoRake::Lib::BaseTask
5
5
  FORWARD_RULES = {
6
- enviro: ->(enviro) { "-#{enviro}" },
7
- folder: ->(folder) { "-local-folder #{folder}"},
8
- list: '-list',
9
- get_last: '-get-last',
10
- get: '-get',
11
- archive: '-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
- cmd << forward_options(:list, :get_last, :get, :archive).compact.first || '-list'
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 = "Missing files to be processed"
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 = self.class.namespace || ''
44
- ns_with_enviro = ns.split(':').any? {|s| s == options[:enviro]}
45
- ns = "#{ns}:#{options[:enviro]}" unless ns_with_enviro
46
- "#{ns}:#{task_name || self.class.task}"
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
@@ -28,11 +28,11 @@ class EcoRake
28
28
  end
29
29
 
30
30
  def base_command
31
- "rake"
31
+ 'rake'
32
32
  end
33
33
 
34
34
  def target_task
35
- raise "In a hub you should re-write this method"
35
+ raise 'In a hub you should re-write this method'
36
36
  end
37
37
  end
38
38
  end
@@ -3,7 +3,7 @@ class EcoRake
3
3
  module DefaultLookup
4
4
  class << self
5
5
  def included(base)
6
- super(base)
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
- kargs.merge!(default: symbol_resolver(default_lookup, as: %i[method const])) unless default_lookup == :not_used
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
- kargs.merge!(default: symbol_resolver(default_lookup, as: %i[method const])) unless default_lookup == :not_used
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
@@ -7,7 +7,7 @@ class EcoRake
7
7
  module Forwarding
8
8
  class << self
9
9
  def included(base)
10
- super(base)
10
+ super
11
11
  base.extend ClassMethods
12
12
  base.attr_inheritable(:options_proxy) {|value, subclass| value&.deep_dup(subclass)}
13
13
  end
@@ -9,7 +9,7 @@ class EcoRake
9
9
  class_resolver :item_class, EcoRake::Options::Set
10
10
 
11
11
  autoloads_children_of :item_class
12
- autoload_namespace_ignore "EcoRake::Options"
12
+ autoload_namespace_ignore 'EcoRake::Options'
13
13
 
14
14
  class << self
15
15
  include Enumerable
@@ -3,7 +3,7 @@ class EcoRake
3
3
  module Parental
4
4
  class << self
5
5
  def included(base)
6
- super(base)
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
@@ -6,7 +6,7 @@ class EcoRake
6
6
  module Options
7
7
  class << self
8
8
  def included(base)
9
- super(base)
9
+ super
10
10
  base.extend ClassMethods
11
11
  base.class_resolver :option_class, EcoRake::Option
12
12
  base.send :include, EcoRake::Options::Parental
@@ -32,6 +32,7 @@ Exception.class_eval do
32
32
  String(message) + super()
33
33
  end
34
34
  end
35
+
35
36
  extend mod
36
37
  end
37
38
 
@@ -41,6 +42,7 @@ Exception.class_eval do
41
42
  super() + String(message)
42
43
  end
43
44
  end
45
+
44
46
  extend mod
45
47
  end
46
48
  end
@@ -2,7 +2,7 @@ class EcoRake
2
2
  module RakeTask
3
3
  class << self
4
4
  def included(base)
5
- super(base)
5
+ super
6
6
  base.send :include, EcoRake::Default
7
7
  end
8
8
  end
@@ -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
@@ -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.freeze
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
@@ -7,7 +7,7 @@ class EcoRake
7
7
  module Shell
8
8
  class << self
9
9
  def included(base)
10
- super(base)
10
+ super
11
11
  base.send :include, Command
12
12
  base.send :include, Files
13
13
  base.send :include, Gpg
@@ -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 && subject.downcase.include?(enviro.downcase)
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
@@ -6,7 +6,7 @@ class EcoRake
6
6
  module Utils
7
7
  class << self
8
8
  def included(base)
9
- super(base)
9
+ super
10
10
  base.extend ClassMethods
11
11
  base.send :include, Mailing
12
12
  base.send :include, Timing
@@ -1,5 +1,5 @@
1
1
  require 'rake-commander'
2
2
 
3
3
  class EcoRake < RakeCommander
4
- VERSION = '0.2.6'.freeze
4
+ VERSION = '0.2.7'.freeze
5
5
  end
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 "EcoRake::Tasks"
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'] == "true"
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.6
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-09 00:00:00.000000000 Z
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
@@ -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