eco-rake 0.2.6 → 0.2.8

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -4
  3. data/eco-rake.gemspec +2 -3
  4. data/lib/eco-rake/base/method_helpers.rb +7 -3
  5. data/lib/eco-rake/base/symbol_resolver.rb +7 -4
  6. data/lib/eco-rake/base.rb +3 -1
  7. data/lib/eco-rake/default/const.rb +5 -3
  8. data/lib/eco-rake/default.rb +1 -1
  9. data/lib/eco-rake/lib/concern/enviro.rb +2 -1
  10. data/lib/eco-rake/lib/export/payload.rb +10 -1
  11. data/lib/eco-rake/lib/files/purge.rb +2 -1
  12. data/lib/eco-rake/lib/files/sftp.rb +18 -8
  13. data/lib/eco-rake/lib/people/base_task.rb +2 -1
  14. data/lib/eco-rake/lib/people/sync_launch.rb +11 -3
  15. data/lib/eco-rake/lib/people/sync_options.rb +1 -0
  16. data/lib/eco-rake/lib/people/sync_process.rb +10 -8
  17. data/lib/eco-rake/lib/people/sync_rely.rb +10 -4
  18. data/lib/eco-rake/lib/task/runner_launch.rb +45 -2
  19. data/lib/eco-rake/lib/task/runner_options.rb +1 -0
  20. data/lib/eco-rake/lib/task/runner_rely.rb +4 -3
  21. data/lib/eco-rake/option/default_lookup.rb +7 -3
  22. data/lib/eco-rake/option/mirror.rb +1 -1
  23. data/lib/eco-rake/option/parented.rb +1 -1
  24. data/lib/eco-rake/options/default_lookup.rb +19 -3
  25. data/lib/eco-rake/options/forwarding.rb +1 -1
  26. data/lib/eco-rake/options/library.rb +4 -2
  27. data/lib/eco-rake/options/parental.rb +3 -1
  28. data/lib/eco-rake/options.rb +1 -1
  29. data/lib/eco-rake/patches/exception.rb +2 -0
  30. data/lib/eco-rake/rake_task.rb +1 -1
  31. data/lib/eco-rake/shell/command.rb +3 -0
  32. data/lib/eco-rake/shell/gpg.rb +1 -1
  33. data/lib/eco-rake/shell.rb +1 -1
  34. data/lib/eco-rake/subtask.rb +12 -0
  35. data/lib/eco-rake/utils/mailer.rb +1 -36
  36. data/lib/eco-rake/utils/mailing.rb +5 -5
  37. data/lib/eco-rake/utils.rb +1 -1
  38. data/lib/eco-rake/version.rb +1 -1
  39. data/lib/eco-rake.rb +2 -2
  40. metadata +18 -18
  41. data/lib/eco-rake/tasks.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6f834edf2918e4ff4e45cfcf538da2e59b632fad4222a3b996f5ab00c60fb25
4
- data.tar.gz: 1f0a90c3242171b560b6adb848e50fc58cd569e61e915e7e9363e6c50c4c6266
3
+ metadata.gz: c6fabd5ceba4d8f3155cfa518e17d521805fff0337cc2174fc0566639acbf004
4
+ data.tar.gz: cc02aabc724d838121de30b6c412955c2c057e0feaa0478eb7668ee81096062b
5
5
  SHA512:
6
- metadata.gz: b619ed8b4ebdf32cb30fdef61f5821d821c1338464e3cfe5d2331df930f00582c0c008c1fe3dac53744b328e4d126a8609f87c71d647889028215f9b709e0895
7
- data.tar.gz: c90b0316f090eec3f5ed131a0bfd808e75ca190f38c8f5f447524161de88c43f39aafe0d9db91a6882c4d7bd70a62ece823a3fde56cdfdc71062eee178d934a6
6
+ metadata.gz: 042554b1170812037e05561744f1bbf1735ba5729fa9fd1138c34f2e86c8c31e468447b3872ca0bc2bdde39d30c21bafd86eb47fe5eed1a72f5408fd3c59b5ec
7
+ data.tar.gz: bcdb45fd4800485968744f94cee82fa0bc136cffb3c79031792fd3312722463254a2292790500f485c0240f66ed14ce75f4cf0dffd63573ec8c50d761f087cd8
data/CHANGELOG.md CHANGED
@@ -2,18 +2,42 @@
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.8] - 2025-02-20
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
+ - `REMOTE_ARCHIVE` [Boolean] whether or not should archive remote files.
10
+ - Integration option for target `space`
11
+ - (sub)tasks declarion and invokation as `Enum`
12
+
13
+ ### Changed
14
+
15
+ - code tidy up
16
+ - upgrade core gem dependency
12
17
 
13
18
  ### Fixed
14
19
 
20
+ - typo on `Options::Library#names`
21
+
22
+ ## [0.2.7] - 2024-12-16
23
+
24
+ ### Added
25
+
26
+ - `EcoRake::Lib::People::SyncLaunch`
27
+ - New constant `TARGET_NAMESPACE`: to build up the target task based on a different namespace (i.e. not nested).
28
+
15
29
  ### Changed
16
30
 
31
+ - code tidy up
32
+
33
+ ## [0.2.6] - 2024-12-09
34
+
35
+ ### Added
36
+
37
+ - `EcoRake::Lib::People::SyncLaunch` new constant `join_files`
38
+ - To specify the integration to use the target folder in raw
39
+ - Which will use all the files with matching pattern within.
40
+
17
41
  ## [0.2.5] - 2024-10-01
18
42
 
19
43
  ### Added
data/eco-rake.gemspec CHANGED
@@ -24,14 +24,13 @@ Gem::Specification.new do |spec|
24
24
  spec.required_ruby_version = '>= 3.2.2'
25
25
 
26
26
  spec.add_development_dependency "rake", ">= 13.0.6", "< 14"
27
+ spec.add_development_dependency "redcarpet", ">= 3.6.0", "< 4"
27
28
  spec.add_development_dependency "rspec", ">= 3.10.0", "< 4"
28
29
  spec.add_development_dependency "yard", ">= 0.9.34", "< 1"
29
- spec.add_development_dependency "redcarpet", ">= 3.6.0", "< 4"
30
30
 
31
- #spec.add_dependency 'aws-sdk-s3', '>= 1.142.0', '< 2'
32
31
  spec.add_dependency 'aws-sdk-ses', '~> 1', '>= 1.58.0'
33
32
  spec.add_dependency 'dotenv', '~> 3'
34
33
  spec.add_dependency 'nokogiri', '>= 1.13', '< 1.17'
35
- spec.add_dependency 'rake-commander', '~> 0.4'
34
+ spec.add_dependency 'rake-commander', '~> 0.4.1'
36
35
  spec.add_dependency 'sendgrid-ruby', '~> 6.7.0'
37
36
  end
@@ -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
@@ -6,12 +6,14 @@ require_relative 'shell'
6
6
  require_relative 'rake_task'
7
7
  require_relative 'option'
8
8
  require_relative 'options'
9
+ require_relative 'subtask'
9
10
 
10
11
  class EcoRake
11
12
  module Base
12
13
  class << self
13
14
  def included(base)
14
- super(base)
15
+ super
16
+
15
17
  base.autoloads_children_of RakeCommander
16
18
  base.extend ClassMethods
17
19
  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
@@ -6,7 +6,8 @@ class EcoRake
6
6
 
7
7
  class << self
8
8
  def included(base)
9
- super(base)
9
+ super
10
+
10
11
  base.option '-e', '--enviro ENVIRO', default_lookup: :default_enviro
11
12
  end
12
13
  end
@@ -11,6 +11,7 @@ class EcoRake
11
11
  INCLUDED_OPTIONS = %i[csv simulate].freeze
12
12
  FORWARD_RULES = {
13
13
  enviro: ->(enviro) { "-#{enviro}" },
14
+ space: :mirror,
14
15
  simulate: '-simulate',
15
16
  csv: '-csv',
16
17
  full: ->(full) { full ? nil : '-delta' },
@@ -20,6 +21,7 @@ class EcoRake
20
21
  options_with_defaults true
21
22
  option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
22
23
  option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true # , default_lookup: :default_enviro
24
+ option '-w', '--space SPACE', String, desc: 'Target space of the envionment (i.e. uat)'
23
25
  option '-f', '--[no-]full', TrueClass, default: false, desc: 'If the PAYLOAD file is a full file (false: means delta)'
24
26
  option '-c', '--csv', TrueClass, default: true, desc: 'Generate files in csv format?'
25
27
  option '-a', '--asat [DATE]', Time, default: Time.now.iso8601, desc: 'Specifies the date when the export was done (default: now).' do |value|
@@ -63,14 +65,21 @@ class EcoRake
63
65
 
64
66
  def forward_command(use, *opts)
65
67
  raise "Expecting String with usecase. Given: #{use.class}" unless use.is_a?(String)
68
+
66
69
  cmd = [base_command(use)]
67
70
  cmd.push(*forward_options(*self.class::INCLUDED_OPTIONS, *opts))
71
+
68
72
  cmd = yield(cmd) if block_given?
73
+
69
74
  string_cmd(*cmd)
70
75
  end
71
76
 
72
77
  def base_command(use = nil)
73
- string_cmd(ruby_runner, forward_option(:enviro), use)
78
+ string_cmd(
79
+ ruby_runner,
80
+ forward_option(:enviro),
81
+ use
82
+ )
74
83
  end
75
84
  end
76
85
  end
@@ -5,12 +5,13 @@ class EcoRake
5
5
  options_with_defaults true
6
6
 
7
7
  option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
8
+ option '-w', '--space SPACE', String, desc: 'Target space of the envionment (i.e. uat)'
8
9
  option '-d', '--folder NAME', desc: 'Source local folder'
9
10
  option '-l', '--list', TrueClass, desc: 'Lists files that will be deleted'
10
11
  option '-o', '--older-than [DAYS]', Integer, desc: 'Number of days files to archive should be older than'
11
12
  option '-r', '--remove', TrueClass, desc: "It deletes those files"
12
13
 
13
- def task(*_args)
14
+ def task(*_args) # rubocop:disable Metrics/AbcSize
14
15
  if target_files.empty?
15
16
  puts "There were no files in folder '#{source_folder}' to be #{str_op}"
16
17
  elsif options[:list]
@@ -3,12 +3,13 @@ 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
+ space: :mirror,
8
+ folder: ->(folder) { "-local-folder #{folder}"},
9
+ list: '-list',
10
+ get_last: '-get-last',
11
+ get: '-get',
12
+ archive: '-archive',
12
13
  file_pattern: ->(str) { "-file-pattern-const #{str}"},
13
14
  remote_subfolder: ->(sub) { "-remote-subfolder #{sub}"}
14
15
  }.freeze
@@ -16,6 +17,7 @@ class EcoRake
16
17
  options_with_defaults true
17
18
 
18
19
  option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
20
+ option '-w', '--space SPACE', String, desc: 'Target space of the envionment (i.e. uat)'
19
21
  option '-d', '--folder NAME', default: '.', desc: 'Source local folder'
20
22
  option '-l', '--list', TrueClass, desc: 'Lists available CSV feed files'
21
23
  option '-g', '--get', TrueClass, desc: 'Gets all available CSV feed files'
@@ -38,7 +40,10 @@ class EcoRake
38
40
  def sftp_command
39
41
  cmd = [base_command]
40
42
  cmd << forward_option(:folder)
41
- cmd << forward_options(:list, :get_last, :get, :archive).compact.first || '-list'
43
+
44
+ forwarded = forward_options(:list, :get_last, :get, :archive).compact.first
45
+ cmd << (forwarded || '-list')
46
+
42
47
  cmd.push(*forward_options(:remote_subfolder, :file_pattern))
43
48
  cmd << '-no-people'
44
49
  cmd = yield(cmd) if block_given?
@@ -46,7 +51,12 @@ class EcoRake
46
51
  end
47
52
 
48
53
  def base_command
49
- string_cmd(ruby_runner, forward_option(:enviro), '-sftp')
54
+ string_cmd(
55
+ ruby_runner,
56
+ forward_option(:enviro),
57
+ forward_option(:space),
58
+ '-sftp'
59
+ )
50
60
  end
51
61
  end
52
62
  end
@@ -3,7 +3,8 @@ class EcoRake
3
3
  module People
4
4
  class BaseTask < EcoRake::Lib::BaseTask
5
5
  FORWARD_RULES = {
6
- enviro: ->(enviro) { "-#{enviro}" }
6
+ enviro: ->(enviro) { "-#{enviro}" },
7
+ space: :mirror
7
8
  }.freeze
8
9
 
9
10
  options_with_defaults true
@@ -4,6 +4,7 @@ class EcoRake
4
4
  # @todo on_error_email to ensure always notified
5
5
  # @todo ping some back-end that it was run
6
6
  # - Should be able to log at debug level.
7
+ # @note in integration repos this is used to be called `run:hris`
7
8
  class SyncLaunch < EcoRake::Lib::People::BaseTask
8
9
  ADDITIONAL_OPTIONS = %i[only_stats no_policy simulate no_email].freeze
9
10
  FORWARD_RULES = {
@@ -31,6 +32,7 @@ class EcoRake
31
32
  def task(*_args)
32
33
  return missing_files_notify unless latest_file
33
34
  return process_deltas if delta?
35
+
34
36
  process_full_file if full? || delta_last?
35
37
  end
36
38
 
@@ -53,8 +55,9 @@ class EcoRake
53
55
  end
54
56
 
55
57
  def missing_files_notify
56
- msg = "Missing files to be processed"
58
+ msg = 'Missing files to be processed'
57
59
  puts msg
60
+
58
61
  exit 1 if options[:simulate]
59
62
  exit 1 if options[:no_email]
60
63
  exit 1 unless (inbox = mail_to)
@@ -81,7 +84,12 @@ class EcoRake
81
84
 
82
85
  # Generate command string to get people
83
86
  def people_get_command
84
- string_cmd(ruby_runner, forward_option(:enviro), '-get-people')
87
+ string_cmd(
88
+ ruby_runner,
89
+ forward_option(:enviro),
90
+ forward_option(:space),
91
+ '-get-people'
92
+ )
85
93
  end
86
94
 
87
95
  # Base command scoping.
@@ -118,7 +126,7 @@ class EcoRake
118
126
  snapshot_mode.to_s.downcase.to_sym == :delta_last
119
127
  end
120
128
 
121
- # Amont the `target_files` the last in alphabetic order.
129
+ # Among the `target_files`, the last in alphabetic order.
122
130
  def latest_file
123
131
  @latest_file ||= ''.then do
124
132
  next options[:folder] if join_files
@@ -4,6 +4,7 @@ class EcoRake
4
4
  class SyncOptions < EcoRake::Options::Set
5
5
  option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
6
6
  option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
7
+ option '-w', '--space SPACE', String, desc: 'Target space of the envionment (i.e. uat)'
7
8
  option '-c', '--schema NAME', "Target person schema."
8
9
  option '-d', '--folder NAME', desc: 'Source local folder'
9
10
  option '-o', '--only-stats', TrueClass, desc: 'To display only stats in the feedback'
@@ -2,6 +2,7 @@ class EcoRake
2
2
  module Lib
3
3
  module People
4
4
  # The top level task that organizes all the people sync
5
+ # @note in integration repos this is used to be called `run:feed`
5
6
  class SyncProcess < EcoRake::Lib::People::SyncRely
6
7
  attr_const :do_decrypt, default: false
7
8
  attr_const :pull_driver, default: 'sftp'
@@ -11,10 +12,11 @@ class EcoRake
11
12
  option_reopen :enviro, default_lookup: :target_enviro
12
13
 
13
14
  attr_const :local_folder, default: '.'
14
- attr_const :mail_to
15
-
16
15
  option_reopen :folder, default_lookup: :local_folder
17
16
 
17
+ attr_const :mail_to
18
+ attr_const :remote_archive, default: true
19
+
18
20
  def task(*_args)
19
21
  upsert_local_dir(options[:folder])
20
22
  sh_continue pull_file
@@ -23,7 +25,7 @@ class EcoRake
23
25
  sh_continue rake_sync_command
24
26
  return if options[:simulate]
25
27
 
26
- sh_continue rake_sftp_archive if pull_driver == 'sftp'
28
+ sh_continue rake_sftp_archive if remote_archive && pull_driver == 'sftp'
27
29
  sh_continue rake_files_purge('cache')
28
30
  sh_continue rake_files_purge('requests')
29
31
  end
@@ -40,15 +42,15 @@ class EcoRake
40
42
  end
41
43
 
42
44
  def rake_sftp_get
43
- rake_command('csv:sftp', *forward_options(:enviro, :folder), '-t')
45
+ rake_command('csv:sftp', *forward_options(:enviro, :space, :folder), '-t')
44
46
  end
45
47
 
46
48
  def rake_url_get
47
- rake_command("csv:#{options[:enviro]}:url", *forward_options(:folder))
49
+ rake_command("csv:#{options[:enviro]}:url", *forward_options(:space, :folder))
48
50
  end
49
51
 
50
52
  def rake_sftp_archive
51
- rake_command('csv:sftp', *forward_options(:enviro, :folder), '-a')
53
+ rake_command('csv:sftp', *forward_options(:enviro, :space, :folder), '-a')
52
54
  end
53
55
 
54
56
  def rake_decrypt
@@ -56,7 +58,7 @@ class EcoRake
56
58
  end
57
59
 
58
60
  def rake_files_purge(folder, operation: '--remove')
59
- rake_command('logs:purge', *forward_options(:enviro), "-d #{folder}", operation)
61
+ rake_command('logs:purge', *forward_options(:enviro, :space), "-d #{folder}", operation)
60
62
  end
61
63
 
62
64
  def failed_decryption_notify
@@ -64,7 +66,7 @@ class EcoRake
64
66
  puts msg
65
67
  exit 1 if options[:simulate]
66
68
  exit 1 if options[:no_email]
67
- exit 1 unless inbox = mail_to
69
+ exit 1 unless (inbox = mail_to)
68
70
 
69
71
  email(enviro: target_enviro, to: inbox, subject: msg, body: msg)
70
72
  exit 1
@@ -5,6 +5,7 @@ class EcoRake
5
5
  class SyncRely < EcoRake::Lib::People::BaseTask
6
6
  FORWARD_RULES = {
7
7
  enviro: :mirror,
8
+ space: :mirror,
8
9
  schema: :mirror,
9
10
  folder: :mirror,
10
11
  only_stats: :mirror,
@@ -17,6 +18,7 @@ class EcoRake
17
18
  option_forwarding(**FORWARD_RULES)
18
19
 
19
20
  attr_const :target_task
21
+ attr_const :target_namespace
20
22
 
21
23
  def task(*_args)
22
24
  sh_continue rake_sync_command
@@ -40,10 +42,14 @@ class EcoRake
40
42
  end
41
43
 
42
44
  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}"
45
+ ns = target_namespace
46
+ unless ns
47
+ ns = self.class.namespace || ''
48
+ ns_with_enviro = ns.split(':').any? {|s| s == options[:enviro]}
49
+ ns = [ns, options[:enviro]].compact.join(':') unless ns_with_enviro
50
+ end
51
+
52
+ [ns, task_name || self.class.task].compact.join(':')
47
53
  end
48
54
  end
49
55
  end
@@ -4,6 +4,7 @@ class EcoRake
4
4
  class RunnerLaunch < EcoRake::Lib::BaseTask
5
5
  FORWARD_RULES = {
6
6
  enviro: ->(enviro) { "-#{enviro}"},
7
+ space: :mirror,
7
8
  simulate: '-simulate'
8
9
  }.freeze
9
10
 
@@ -13,20 +14,62 @@ class EcoRake
13
14
  attr_const :target_enviro, required: true
14
15
  option_reopen :enviro, default_lookup: :target_enviro
15
16
 
17
+ option_reopen :task, type: [], desc: 'Target task to run', required: true
18
+
19
+ # Offer native way to declare tasks
20
+ class << self
21
+ def subtask(name, desc = nil, **kargs, &block)
22
+ EcoRake::Subtask.new(name, desc, **kargs, &block).tap do |subtask|
23
+ raise "Task '#{name}' is already defined" if subtasks.key?(subtask.name)
24
+
25
+ option_get(:task).tap do |option|
26
+ option.enum_options.push(subtask.name)
27
+ subtasks[subtask.name] = subtask
28
+ end
29
+ end
30
+ end
31
+
32
+ def subtasks
33
+ @subtasks ||= {}
34
+ end
35
+ end
36
+
16
37
  option_forwarding(**FORWARD_RULES)
17
38
 
39
+ def task(*args)
40
+ if (callback = target_subtask.callback)
41
+ instance_exec(*args, &callback)
42
+ elsif respond_to?(target_subtask.name, true)
43
+ send(target_subtask.name)
44
+ else
45
+ msg = "Undefined method to perform '#{target_subtask.name}'"
46
+ raise msg
47
+ end
48
+ end
49
+
50
+ protected
51
+
52
+ def target_subtask
53
+ subtask_name = options[:task].to_sym
54
+ self.class.subtasks[subtask_name].tap do |ts|
55
+ next if ts
56
+
57
+ raise "Couldn't find any (sub)task named '#{subtask_name}'"
58
+ end
59
+ end
60
+
18
61
  private
19
62
 
20
63
  def command(*args)
21
64
  cmd = [ruby_runner]
22
- cmd.push(*forward_options(:enviro, :simulate))
65
+ cmd.push(*forward_options(:enviro, :space, :simulate))
23
66
  cmd.push(*args)
24
67
  cmd = yield(cmd) if block_given?
25
68
  string_cmd(*cmd)
26
69
  end
27
70
 
28
71
  def people_get_command
29
- string_cmd(ruby_runner, forward_option(:enviro), '-get-people')
72
+ string_cmd(ruby_runner, *forward_options(:enviro, :space), '-get-people')
30
73
  end
31
74
  end
32
75
  end
@@ -4,6 +4,7 @@ class EcoRake
4
4
  class RunnerOptions < EcoRake::Options::Set
5
5
  option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
6
6
  option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
7
+ option '-w', '--space SPACE', String, desc: 'Target space of the envionment (i.e. uat)'
7
8
  option '-t', '--task NAME', String, desc: 'Target task to run', required: true
8
9
  end
9
10
  end
@@ -4,7 +4,8 @@ class EcoRake
4
4
  class RunnerRely < EcoRake::Lib::BaseTask
5
5
  FORWARD_RULES = {
6
6
  simulate: :mirror,
7
- task: :mirror
7
+ task: :mirror,
8
+ space: :mirror
8
9
  }.freeze
9
10
 
10
11
  options_with_defaults true
@@ -28,11 +29,11 @@ class EcoRake
28
29
  end
29
30
 
30
31
  def base_command
31
- "rake"
32
+ 'rake'
32
33
  end
33
34
 
34
35
  def target_task
35
- raise "In a hub you should re-write this method"
36
+ raise 'In a hub you should re-write this method'
36
37
  end
37
38
  end
38
39
  end
@@ -6,7 +6,8 @@ class EcoRake
6
6
  module DefaultLookup
7
7
  class << self
8
8
  def included(base)
9
- super(base)
9
+ super
10
+
10
11
  base.extend EcoRake::Base::SymbolResolver
11
12
  end
12
13
  end
@@ -14,6 +15,7 @@ class EcoRake
14
15
  # Default may be a lookup
15
16
  def default(&block)
16
17
  return @default unless default_lookup?
18
+
17
19
  result = self.class.safe_call(@default, parent, &block)
18
20
  result = self.class.safe_call(result, &block) if [Proc, Method].any? {|k| result.is_a?(k)}
19
21
  result
@@ -23,9 +25,11 @@ class EcoRake
23
25
  # @return [Class, NilClass]
24
26
  def type_coercion
25
27
  return @type_coercion if @type_coercion
26
- return nil unless default?
28
+ return unless default?
29
+
27
30
  value = default
28
- return nil if value.nil?
31
+ return if value.nil?
32
+
29
33
  value.class
30
34
  end
31
35
 
@@ -24,7 +24,7 @@ class EcoRake
24
24
  opt = name_hyphened
25
25
  # puts "boolean_mirror (#{value}): #{opt}" if name == :no_get
26
26
 
27
- return nil unless [TrueClass, NilClass, FalseClass].any? {|klass| type_coercion == klass}
27
+ return unless [TrueClass, NilClass, FalseClass].any? {|klass| type_coercion == klass}
28
28
 
29
29
  enabled_value = !boolean_name? || [TrueClass, NilClass].any? {|klass| type_coercion == klass}
30
30
  return opt if value == enabled_value
@@ -3,7 +3,7 @@ class EcoRake
3
3
  module Parented
4
4
  attr_accessor :parent
5
5
 
6
- def initialize(*args, _parent: nil, **kargs, &block)
6
+ def initialize(*args, _parent: nil, **kargs, &block) # rubocop:disable Lint/UnderscorePrefixedVariableName
7
7
  self.parent = _parent
8
8
  super(*args, **kargs, &block)
9
9
  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
@@ -17,6 +17,7 @@ class EcoRake
17
17
  # Iterator
18
18
  def each(&block)
19
19
  return to_enum(:each) unless block_given?
20
+
20
21
  sets.values.each(&block)
21
22
  end
22
23
 
@@ -29,12 +30,13 @@ class EcoRake
29
30
  # @return [Boolean]
30
31
  def set?(name)
31
32
  raise "Expected String or Symbol. Given: #{name.class}" unless name.respond_to?(:to_sym)
33
+
32
34
  sets.key?(name.to_sym)
33
35
  end
34
36
 
35
37
  # @return [Array<Symbol>] names list of all available option sets.
36
38
  def names
37
- setes.keys
39
+ sets.keys
38
40
  end
39
41
 
40
42
  # Add a new options set.
@@ -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
@@ -0,0 +1,12 @@
1
+ class EcoRake
2
+ class Subtask
3
+ attr_reader :name, :desc, :params, :callback
4
+
5
+ def initialize(name, desc = nil, **kargs, &callback)
6
+ @name = name.to_sym
7
+ @desc = desc || kargs.delete(:desc)
8
+ @params = kargs
9
+ @callback = callback
10
+ end
11
+ end
12
+ end
@@ -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.8'.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.8
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: 2025-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -31,12 +31,12 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '14'
33
33
  - !ruby/object:Gem::Dependency
34
- name: rspec
34
+ name: redcarpet
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 3.10.0
39
+ version: 3.6.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '4'
@@ -46,50 +46,50 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.10.0
49
+ version: 3.6.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '4'
53
53
  - !ruby/object:Gem::Dependency
54
- name: yard
54
+ name: rspec
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.9.34
59
+ version: 3.10.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: '1'
62
+ version: '4'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 0.9.34
69
+ version: 3.10.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: '1'
72
+ version: '4'
73
73
  - !ruby/object:Gem::Dependency
74
- name: redcarpet
74
+ name: yard
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 3.6.0
79
+ version: 0.9.34
80
80
  - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: '4'
82
+ version: '1'
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 3.6.0
89
+ version: 0.9.34
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
- version: '4'
92
+ version: '1'
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: aws-sdk-ses
95
95
  requirement: !ruby/object:Gem::Requirement
@@ -150,14 +150,14 @@ dependencies:
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: '0.4'
153
+ version: 0.4.1
154
154
  type: :runtime
155
155
  prerelease: false
156
156
  version_requirements: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: '0.4'
160
+ version: 0.4.1
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: sendgrid-ruby
163
163
  requirement: !ruby/object:Gem::Requirement
@@ -245,7 +245,7 @@ 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
248
+ - lib/eco-rake/subtask.rb
249
249
  - lib/eco-rake/utils.rb
250
250
  - lib/eco-rake/utils/mailer.rb
251
251
  - 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