eco-rake 0.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.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.gitlab-ci.yml +13 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +90 -0
  6. data/.yardopts +10 -0
  7. data/CHANGELOG.md +13 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +21 -0
  10. data/README.md +28 -0
  11. data/Rakefile +27 -0
  12. data/eco-rake.gemspec +34 -0
  13. data/lib/eco-rake/base/method_helpers.rb +55 -0
  14. data/lib/eco-rake/base/symbol_resolver.rb +82 -0
  15. data/lib/eco-rake/base.rb +25 -0
  16. data/lib/eco-rake/custom.rb +5 -0
  17. data/lib/eco-rake/default/const.rb +46 -0
  18. data/lib/eco-rake/default.rb +12 -0
  19. data/lib/eco-rake/lib/base_task.rb +9 -0
  20. data/lib/eco-rake/lib/concern/base.rb +21 -0
  21. data/lib/eco-rake/lib/concern/enviro.rb +23 -0
  22. data/lib/eco-rake/lib/concern/local_folder.rb +23 -0
  23. data/lib/eco-rake/lib/concern/person_schema.rb +24 -0
  24. data/lib/eco-rake/lib/concern.rb +11 -0
  25. data/lib/eco-rake/lib/export/payload.rb +78 -0
  26. data/lib/eco-rake/lib/export.rb +8 -0
  27. data/lib/eco-rake/lib/files/decrypt.rb +48 -0
  28. data/lib/eco-rake/lib/files/purge.rb +73 -0
  29. data/lib/eco-rake/lib/files/sftp.rb +49 -0
  30. data/lib/eco-rake/lib/files.rb +10 -0
  31. data/lib/eco-rake/lib/notify/mailer.rb +24 -0
  32. data/lib/eco-rake/lib/notify.rb +8 -0
  33. data/lib/eco-rake/lib/options.rb +8 -0
  34. data/lib/eco-rake/lib/people/base_task.rb +16 -0
  35. data/lib/eco-rake/lib/people/sync_launch.rb +131 -0
  36. data/lib/eco-rake/lib/people/sync_options.rb +15 -0
  37. data/lib/eco-rake/lib/people/sync_process.rb +48 -0
  38. data/lib/eco-rake/lib/people/sync_rely.rb +47 -0
  39. data/lib/eco-rake/lib/people.rb +12 -0
  40. data/lib/eco-rake/lib/task/runner_launch.rb +34 -0
  41. data/lib/eco-rake/lib/task/runner_options.rb +11 -0
  42. data/lib/eco-rake/lib/task/runner_rely.rb +40 -0
  43. data/lib/eco-rake/lib/task.rb +10 -0
  44. data/lib/eco-rake/lib.rb +15 -0
  45. data/lib/eco-rake/option/default_lookup.rb +39 -0
  46. data/lib/eco-rake/option/mirror.rb +34 -0
  47. data/lib/eco-rake/option/parented.rb +12 -0
  48. data/lib/eco-rake/option.rb +19 -0
  49. data/lib/eco-rake/options/default_lookup.rb +29 -0
  50. data/lib/eco-rake/options/forwarding/proxy.rb +125 -0
  51. data/lib/eco-rake/options/forwarding/rule.rb +82 -0
  52. data/lib/eco-rake/options/forwarding.rb +45 -0
  53. data/lib/eco-rake/options/library.rb +81 -0
  54. data/lib/eco-rake/options/parental.rb +37 -0
  55. data/lib/eco-rake/options/set.rb +21 -0
  56. data/lib/eco-rake/options.rb +25 -0
  57. data/lib/eco-rake/rake_task.rb +10 -0
  58. data/lib/eco-rake/shell/command.rb +59 -0
  59. data/lib/eco-rake/shell/eco_helpers.rb +10 -0
  60. data/lib/eco-rake/shell/files.rb +83 -0
  61. data/lib/eco-rake/shell/gpg.rb +54 -0
  62. data/lib/eco-rake/shell.rb +18 -0
  63. data/lib/eco-rake/tasks.rb +12 -0
  64. data/lib/eco-rake/utils/mailer.rb +91 -0
  65. data/lib/eco-rake/utils/mailing.rb +19 -0
  66. data/lib/eco-rake/utils/timing.rb +9 -0
  67. data/lib/eco-rake/utils.rb +19 -0
  68. data/lib/eco-rake/version.rb +5 -0
  69. data/lib/eco-rake.rb +16 -0
  70. metadata +271 -0
@@ -0,0 +1,78 @@
1
+ # Use case for special integrations. It requires some use cases to be present
2
+ # 1. `-export-select-options`
3
+ # 2. `-export-registers`
4
+ # 3. `-export-pack`
5
+ # 4. `-export-sftp-push`
6
+ require 'optparse/time'
7
+ class EcoRake
8
+ module Lib
9
+ module Export
10
+ class Payload < EcoRake::Lib::BaseTask
11
+ INCLUDED_OPTIONS = %i[csv simulate].freeze
12
+ FORWARD_RULES = {
13
+ enviro: ->(enviro) { "-#{enviro}" },
14
+ simulate: '-simulate',
15
+ csv: '-csv',
16
+ full: ->(full) { full ? nil : '-delta' },
17
+ asat: ->(asat) { "-asatdate #{asat}" }
18
+ }.freeze
19
+
20
+ options_with_defaults true
21
+ option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
22
+ option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true # , default_lookup: :default_enviro
23
+ option '-f', '--[no-]full', TrueClass, default: false, desc: 'If the PAYLOAD file is a full file (false: means delta)'
24
+ option '-c', '--csv', TrueClass, default: true, desc: 'Generate files in csv format?'
25
+ option '-a', '--asat [DATE]', Time, default: Time.now.iso8601, desc: 'Specifies the date when the export was done (default: now).' do |value|
26
+ value&.iso8601
27
+ end
28
+
29
+ option_forwarding(**FORWARD_RULES)
30
+
31
+ def task(*_args)
32
+ sh_chain(commands) do |ok, _res|
33
+ exit 1 unless ok
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def commands
40
+ cmds = []
41
+ cmds << export_select_options
42
+ cmds << export_registers
43
+ cmds << export_pack
44
+ cmds << export_sftp_push unless options[:simulate]
45
+ cmds
46
+ end
47
+
48
+ def export_select_options
49
+ forward_command('-export-select-options')
50
+ end
51
+
52
+ def export_registers
53
+ forward_command('-export-registers')
54
+ end
55
+
56
+ def export_pack
57
+ forward_command('-export-pack', :full, :asat)
58
+ end
59
+
60
+ def export_sftp_push
61
+ base_command('-export-sftp-push')
62
+ end
63
+
64
+ def forward_command(use, *opts)
65
+ raise "Expecting String with usecase. Given: #{use.class}" unless use.is_a?(String)
66
+ cmd = [base_command(use)]
67
+ cmd.push(*forward_options(*self.class::INCLUDED_OPTIONS, *opts))
68
+ cmd = yield(cmd) if block_given?
69
+ string_cmd(*cmd)
70
+ end
71
+
72
+ def base_command(use = nil)
73
+ string_cmd(ruby_runner, forward_option(:enviro), use)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'export/payload'
2
+
3
+ class EcoRake
4
+ module Lib
5
+ module Export
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,48 @@
1
+ class EcoRake
2
+ module Lib
3
+ module Files
4
+ class Decrypt < EcoRake::Lib::BaseTask
5
+ options_with_defaults true
6
+
7
+ option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
8
+ option '-l', '--list', TrueClass, desc: 'Lists available gpg feed files'
9
+ option '-d', '--folder NAME', default: '.', desc: 'Source local folder'
10
+ attr_const :ignore_mdc_error, default: false
11
+
12
+ def task(*_args)
13
+ return display_target_files if options[:list]
14
+ return warn_missing_file if target_files.empty?
15
+ target_files.each do |file|
16
+ delete_file(gpg_to_csv_filename(file))
17
+ sh decrypt_command(file, ignore_mdc_error: ignore_mdc_error)
18
+ end
19
+ delete_file(*target_files, message: "Deleting files from '#{source_folder}'") unless options[:simulate]
20
+ end
21
+
22
+ def display_target_files
23
+ puts "Source gpg files ('#{source_folder}'):"
24
+ target_files.each {|file| puts " • #{File.basename(file)}"}
25
+ end
26
+
27
+ def warn_missing_file
28
+ puts "Could not find any file in folder '#{source_folder}'"
29
+ end
30
+
31
+ private
32
+
33
+ # Amont the `target_files` the last in alphabetic order.
34
+ def latest_file
35
+ @latest_file ||= target_files.last
36
+ end
37
+
38
+ def target_files
39
+ @target_files ||= gpg_files(source_folder)
40
+ end
41
+
42
+ def source_folder
43
+ @source_folder ||= File.expand_path(options[:folder])
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,73 @@
1
+ class EcoRake
2
+ module Lib
3
+ module Files
4
+ class Purge < EcoRake::Lib::BaseTask
5
+ options_with_defaults true
6
+
7
+ option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
8
+ option '-d', '--folder NAME', desc: 'Source local folder'
9
+ option '-l', '--list', TrueClass, desc: 'Lists files that will be deleted'
10
+ option '-o', '--older-than [DAYS]', Integer, desc: 'Number of days files to archive should be older than'
11
+ option '-r', '--remove', TrueClass, desc: "It deletes those files"
12
+
13
+ def task(*_args)
14
+ if target_files.empty?
15
+ puts "There were no files in folder '#{source_folder}' to be #{str_op}"
16
+ elsif options[:list]
17
+ msg = "#{target_files.count} target log files (from '#{source_folder}') will be #{str_op}"
18
+ msg << " to '#{dest_folder}':" unless remove?
19
+ puts msg
20
+ target_files.each {|file| puts " • #{File.basename(file)}"}
21
+ elsif options[:remove]
22
+ delete_file(*target_files, message: "Removing the following #{target_files.count} files from '#{source_folder}':")
23
+ else
24
+ ensure_dest_folder!
25
+ msg = "Moving #{target_files.count} log files from '#{source_folder}' to the '#{dest_folder}' folder:"
26
+ move_file(*target_files, folder: dest_folder, message: msg)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # Based on `older-than` option
33
+ # @return [Array<String>]
34
+ def target_files
35
+ @target_files ||= folder_files(source_folder, older_than: older_than)
36
+ end
37
+
38
+ # Folder where the files will be moved (when applicable)
39
+ def dest_folder
40
+ @dest_folder ||= File.join(source_folder, 'archive').tap do |folder|
41
+ directory folder
42
+ end
43
+ end
44
+
45
+ # It declares the folder as a task and creates it if it doesn't exist
46
+ def ensure_dest_folder!
47
+ directory dest_folder
48
+ Rake::Task[dest_folder].invoke
49
+ end
50
+
51
+ # @return [String]
52
+ def source_folder
53
+ @source_folder ||= File.expand_path(options[:folder])
54
+ end
55
+
56
+ # @return [Integer] number of days the files are older than.
57
+ def older_than
58
+ options[:older_than] || (remove?? 15 : 3)
59
+ end
60
+
61
+ # @return [String]
62
+ def str_op
63
+ remove?? 'deleted' : 'moved'
64
+ end
65
+
66
+ # @return [Boolean] whether the files should be moved or removed/deleted.
67
+ def remove?
68
+ options[:remove]
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,49 @@
1
+ class EcoRake
2
+ module Lib
3
+ module Files
4
+ class Sftp < EcoRake::Lib::BaseTask
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'
12
+ }.freeze
13
+
14
+ options_with_defaults true
15
+
16
+ option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
17
+ option '-d', '--folder NAME', default: '.', desc: 'Source local folder'
18
+ option '-l', '--list', TrueClass, desc: 'Lists available CSV feed files'
19
+ option '-g', '--get', TrueClass, desc: 'Gets all available CSV feed files'
20
+ option '-t', '--get-last', TrueClass, desc: 'Gets the last available CSV feed file'
21
+ option '-a', '--archive', TrueClass, desc: "Moves the remote CSV feed files to the '/Archive' folder"
22
+
23
+ option_forwarding(**FORWARD_RULES)
24
+
25
+ # attr_const :target_enviro, required: true
26
+ # option_reopen :enviro, default_lookup: :target_enviro
27
+
28
+ def task(*_args)
29
+ sh sftp_command
30
+ end
31
+
32
+ private
33
+
34
+ def sftp_command
35
+ cmd = [base_command]
36
+ cmd << forward_option(:folder)
37
+ cmd << forward_options(:list, :get_last, :get, :archive).compact.first || '-list'
38
+ cmd << '-no-people'
39
+ cmd = yield(cmd) if block_given?
40
+ string_cmd(*cmd)
41
+ end
42
+
43
+ def base_command
44
+ string_cmd(ruby_runner, forward_option(:enviro), '-sftp')
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'files/purge'
2
+ require_relative 'files/decrypt'
3
+ require_relative 'files/sftp'
4
+
5
+ class EcoRake
6
+ module Lib
7
+ module Files
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ class EcoRake
2
+ module Lib
3
+ module Notify
4
+ class Mailer < EcoRake::Lib::BaseTask
5
+ option '-t', '--to EMAIL', String, 'Destination recipient', required: true
6
+ option '-s', '--subject SUBJECT', String, 'Subject of the email', required: true
7
+ option '-m', '--body MESSAGE', String, 'The message of the email', required: true
8
+ option '-c', '--cc EMAIL', String, 'CCing someone else'
9
+ option '-b', '--bcc EMAIL', String, 'BCCing someone else'
10
+
11
+ def task(*_args)
12
+ kargs = {
13
+ to: options[:to],
14
+ subject: options[:subject],
15
+ body: options[:body]
16
+ }
17
+ kargs.merge!(cc: options[:cc]) if options[:cc]
18
+ kargs.merge!(bcc: options[:bcc]) if options[:bcc]
19
+ mailer.mail(**kargs)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'notify/mailer'
2
+
3
+ class EcoRake
4
+ module Lib
5
+ module Notify
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'options/usecase'
2
+
3
+ class EcoRake
4
+ module Sample
5
+ module Options
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ class EcoRake
2
+ module Lib
3
+ module People
4
+ class BaseTask < EcoRake::Lib::BaseTask
5
+ FORWARD_RULES = {
6
+ enviro: ->(enviro) { "-#{enviro}" }
7
+ }.freeze
8
+
9
+ options_with_defaults true
10
+ options_use EcoRake::Lib::People::SyncOptions
11
+
12
+ option_forwarding(**FORWARD_RULES)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,131 @@
1
+ class EcoRake
2
+ module Lib
3
+ module People
4
+ # @todo on_error_email to ensure always notified
5
+ # @todo ping some back-end that it was run
6
+ # - Should be able to log at debug level.
7
+ class SyncLaunch < EcoRake::Lib::People::BaseTask
8
+ ADDITIONAL_OPTIONS = %i[only_stats no_policy simulate].freeze
9
+ FORWARD_RULES = {
10
+ schema: ->(schema) { "-schema-id \"#{schema}\"" },
11
+ only_stats: '-feed-only-stats',
12
+ no_policy: '-skip-batch-policy',
13
+ simulate: '-simulate'
14
+ }.freeze
15
+
16
+ attr_const :target_enviro, required: true
17
+ option_reopen :enviro, default_lookup: :target_enviro
18
+
19
+ attr_const :base_usecase, :default_schema, :file_pattern, required: true
20
+ attr_const :snapshot_mode, default: :full
21
+ attr_const :local_folder, default: '.'
22
+ attr_const :mail_to
23
+
24
+ option_reopen :schema, default_lookup: :default_schema, required: true
25
+ option_reopen :folder, default_lookup: :local_folder
26
+
27
+ option_forwarding(**FORWARD_RULES)
28
+
29
+ def task(*_args)
30
+ return missing_files_notify unless latest_file
31
+ return process_deltas if delta?
32
+ return process_full_file if full?
33
+ end
34
+
35
+ private
36
+
37
+ def process_full_file
38
+ sh people_get_command unless options[:no_get]
39
+ sh_continue sync_command(latest_file)
40
+ clear_files unless options[:simulate]
41
+ end
42
+
43
+ def process_deltas
44
+ target_files.each do |file|
45
+ sh sync_command(file)
46
+ next if options[:simulate]
47
+ puts "Deleting file #{file}"
48
+ File.delete(file)
49
+ end
50
+ end
51
+
52
+ def missing_files_notify
53
+ puts "Missing files to be processed"
54
+ exit 1 if options[:simulate]
55
+ exit 1 unless inbox = mail_to
56
+ email_missing_files(enviro: target_enviro, to: inbox)
57
+ exit 1
58
+ end
59
+
60
+ # @yield [cmd] do something to extend the command
61
+ # @yieldparam cmd [Array<String>] the command as this task would generate it.
62
+ # @yieldresult [Array<String>] the final command
63
+ # @return [String] the sync command
64
+ def sync_command(file)
65
+ cmd = []
66
+ cmd << ruby_runner
67
+ cmd << forward_option(:enviro)
68
+ cmd << forward_option(:schema)
69
+ cmd << '-get-partial' if delta?
70
+ cmd << base_command(file)
71
+ cmd.concat(forward_options(*self.class::ADDITIONAL_OPTIONS))
72
+ cmd = yield(cmd) if block_given?
73
+ string_cmd(*cmd)
74
+ end
75
+
76
+ # Generate command string to get people
77
+ def people_get_command
78
+ string_cmd(ruby_runner, forward_option(:enviro), '-get-people')
79
+ end
80
+
81
+ # Base command scoping.
82
+ # @note it ensures basic information is not missing or inconsistent.
83
+ def base_command(file_or_folder)
84
+ raise "Missing target file or folder in #{self.class}" if file_or_folder.to_s.strip.empty?
85
+ usecase = base_usecase.to_sym
86
+ case usecase
87
+ when :hris
88
+ msg = "Inconsistent configuration in #{self.class}. BASE_USECASE is '#{usecase}', "
89
+ msg << "but file SNAPSHOT_MODE is '#{snapshot_mode}'"
90
+ raise msg if delta?
91
+ "-hris-from #{double_quote(file_or_folder)}"
92
+ when :upsert
93
+ "-upsert-from #{double_quote(file_or_folder)}"
94
+ else
95
+ raise ArgumentError, "Unknown use case '#{usecase}'"
96
+ end
97
+ end
98
+
99
+ def full?
100
+ snapshot_mode.to_s.downcase.to_sym == :full
101
+ end
102
+
103
+ def delta?
104
+ mode = snapshot_mode.to_s.downcase.to_sym
105
+ %i[partial delta].any? {|m| m == mode}
106
+ end
107
+
108
+ # Amont the `target_files` the last in alphabetic order.
109
+ def latest_file
110
+ @latest_file ||= target_files.last
111
+ end
112
+
113
+ # @note if there is a file_pattern method or FILE_PATTERN const, it's used as a pattern.
114
+ # @return [Array<String>] the `csv` files of the target folder
115
+ def target_files
116
+ @target_files ||= csv_files(options[:folder], regexp: file_pattern)
117
+ end
118
+
119
+ # Deletes the files identified as target.
120
+ def clear_files
121
+ deleted_files = target_files.each_with_object([]) do |file, deleted|
122
+ next unless File.exist?(file)
123
+ File.delete(file)
124
+ deleted << file
125
+ end
126
+ puts "Deleted these files:\n • #{deleted_files.join("\n • ")}" unless deleted_files.empty?
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,15 @@
1
+ class EcoRake
2
+ module Lib
3
+ module People
4
+ class SyncOptions < EcoRake::Options::Set
5
+ option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
6
+ option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
7
+ option '-c', '--schema NAME', "Target person schema."
8
+ option '-d', '--folder NAME', desc: 'Source local folder'
9
+ option '-o', '--only-stats', TrueClass, desc: 'To display only stats in the feedback'
10
+ option '-b', '--no-policy', FalseClass, desc: 'To skip the batch policy'
11
+ option '-n', '--no-get', FalseClass, desc: 'Skip get people step'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ class EcoRake
2
+ module Lib
3
+ module People
4
+ # The top level task that organizes all the people sync
5
+ class SyncProcess < EcoRake::Lib::People::SyncRely
6
+ attr_const :do_decrypt, default: false
7
+ attr_const :target_task
8
+
9
+ attr_const :target_enviro, required: true
10
+ option_reopen :enviro, default_lookup: :target_enviro
11
+
12
+ attr_const :local_folder, default: '.'
13
+ attr_const :mail_to
14
+
15
+ option_reopen :folder, default_lookup: :local_folder
16
+
17
+ def task(*_args)
18
+ upsert_local_dir(options[:folder])
19
+ sh_continue rake_sftp_get
20
+ sh rake_decrypt if do_decrypt
21
+ sh_continue rake_sync_command
22
+ return if options[:simulate]
23
+ sh_continue rake_sftp_archive
24
+ sh_continue rake_files_purge('cache')
25
+ sh_continue rake_files_purge('requests')
26
+ end
27
+
28
+ private
29
+
30
+ def rake_sftp_get
31
+ rake_command('csv:sftp', *forward_options(:enviro, :folder), '-t')
32
+ end
33
+
34
+ def rake_sftp_archive
35
+ rake_command('csv:sftp', *forward_options(:enviro, :folder), '-a')
36
+ end
37
+
38
+ def rake_decrypt
39
+ array_cmd('rake csv:decrypt', '--', forward_option(:folder)).join(" ")
40
+ end
41
+
42
+ def rake_files_purge(folder, operation: '--remove')
43
+ rake_command('logs:purge', *forward_options(:enviro), "-d #{folder}", operation)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+ class EcoRake
2
+ module Lib
3
+ module People
4
+ # The top level task that organizes all the people sync
5
+ class SyncRely < EcoRake::Lib::People::BaseTask
6
+ FORWARD_RULES = {
7
+ enviro: :mirror,
8
+ schema: :mirror,
9
+ folder: :mirror,
10
+ only_stats: :mirror,
11
+ no_policy: :mirror,
12
+ no_get: :mirror,
13
+ simulate: :mirror
14
+ }.freeze
15
+
16
+ option_forwarding(**FORWARD_RULES)
17
+
18
+ attr_const :target_task
19
+
20
+ def task(*_args)
21
+ sh_continue rake_sync_command
22
+ end
23
+
24
+ private
25
+
26
+ def rake_sync_command
27
+ rake_command(namespaced_task, *forward_options(*FORWARD_RULES.keys - [:enviro]))
28
+ end
29
+
30
+ def rake_command(task_name, *options)
31
+ string_cmd(base_command(task_name), '--', *options)
32
+ end
33
+
34
+ def base_command(task_name = namespaced_task)
35
+ string_cmd('rake', task_name)
36
+ end
37
+
38
+ def namespaced_task(task_name = target_task)
39
+ ns = self.class.namespace || ''
40
+ ns_with_enviro = ns.split(':').any? {|s| s == options[:enviro]}
41
+ ns = ns_with_enviro ? ns : "#{ns}:#{options[:enviro]}"
42
+ "#{ns}:#{task_name || self.class.task}"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'people/sync_options'
2
+ require_relative 'people/base_task'
3
+ require_relative 'people/sync_rely'
4
+ require_relative 'people/sync_process'
5
+ require_relative 'people/sync_launch'
6
+
7
+ class EcoRake
8
+ module Lib
9
+ module People
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ class EcoRake
2
+ module Lib
3
+ module Task
4
+ class RunnerLaunch < EcoRake::Lib::BaseTask
5
+ FORWARD_RULES = {
6
+ enviro: ->(enviro) { "-#{enviro}"},
7
+ simulate: '-simulate'
8
+ }.freeze
9
+
10
+ options_with_defaults true
11
+ options_use EcoRake::Lib::Task::RunnerOptions
12
+
13
+ attr_const :target_enviro, required: true
14
+ option_reopen :enviro, default_lookup: :target_enviro
15
+
16
+ option_forwarding(**FORWARD_RULES)
17
+
18
+ private
19
+
20
+ def command(*args)
21
+ cmd = [ruby_runner]
22
+ cmd.push(*forward_options(:enviro, :simulate))
23
+ cmd.push(*args)
24
+ cmd = yield(cmd) if block_given?
25
+ string_cmd(*cmd)
26
+ end
27
+
28
+ def people_get_command
29
+ string_cmd(ruby_runner, forward_option(:enviro), '-get-people')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ class EcoRake
2
+ module Lib
3
+ module Task
4
+ class RunnerOptions < EcoRake::Options::Set
5
+ option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
6
+ option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
7
+ option '-t', '--task NAME', String, desc: 'Target task to run', required: true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ class EcoRake
2
+ module Lib
3
+ module Task
4
+ class RunnerRely < EcoRake::Lib::BaseTask
5
+ FORWARD_RULES = {
6
+ simulate: :mirror,
7
+ task: :mirror
8
+ }.freeze
9
+
10
+ options_with_defaults true
11
+ options_use EcoRake::Lib::Task::RunnerOptions
12
+
13
+ option_forwarding(**FORWARD_RULES)
14
+
15
+ def task(*_args)
16
+ sh_continue command
17
+ end
18
+
19
+ private
20
+
21
+ def command
22
+ cmd = [base_command]
23
+ cmd << target_task
24
+ cmd << '--'
25
+ cmd << forward_option(:task)
26
+ cmd << forward_option(:simulate)
27
+ string_cmd(*cmd)
28
+ end
29
+
30
+ def base_command
31
+ "rake"
32
+ end
33
+
34
+ def target_task
35
+ raise "In a hub you should re-write this method"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end