lib/eco-rake/lib/people/sync_launch.rb in eco-rake-0.2.5 vs lib/eco-rake/lib/people/sync_launch.rb in eco-rake-0.2.6

- old
+ new

@@ -19,20 +19,21 @@ attr_const :base_usecase, :default_schema, :file_pattern, required: true attr_const :snapshot_mode, default: :full attr_const :local_folder, default: '.' attr_const :mail_to + attr_const :join_files, default: false option_reopen :schema, default_lookup: :default_schema, required: true option_reopen :folder, default_lookup: :local_folder option_forwarding(**FORWARD_RULES) def task(*_args) return missing_files_notify unless latest_file return process_deltas if delta? - return process_full_file if full? || delta_last? + process_full_file if full? || delta_last? end private def process_full_file @@ -54,11 +55,11 @@ def missing_files_notify msg = "Missing files to be processed" puts msg exit 1 if options[:simulate] exit 1 if options[:no_email] - exit 1 unless inbox = mail_to + exit 1 unless (inbox = mail_to) email_missing_files(enviro: target_enviro, to: inbox) exit 1 end @@ -85,16 +86,18 @@ # Base command scoping. # @note it ensures basic information is not missing or inconsistent. def base_command(file_or_folder) raise "Missing target file or folder in #{self.class}" if file_or_folder.to_s.strip.empty? + usecase = base_usecase.to_sym case usecase when :hris msg = "Inconsistent configuration in #{self.class}. BASE_USECASE is '#{usecase}', " msg << "but file SNAPSHOT_MODE is '#{snapshot_mode}'" raise msg if delta? || delta_last? + "-hris-from #{double_quote(file_or_folder)}" when :upsert "-upsert-from #{double_quote(file_or_folder)}" else raise ArgumentError, "Unknown use case '#{usecase}'" @@ -108,31 +111,42 @@ def delta? mode = snapshot_mode.to_s.downcase.to_sym %i[partial delta].any? {|m| m == mode} end + # only last delta (i.e. customer builds deltas based on eP full snapshot) def delta_last? - snapshot_mode.to_s.downcase.to_sym == :delta_last + snapshot_mode.to_s.downcase.to_sym == :delta_last end # Amont the `target_files` the last in alphabetic order. def latest_file - @latest_file ||= target_files.last + @latest_file ||= ''.then do + next options[:folder] if join_files + + target_files.last + end end # @note if there is a file_pattern method or FILE_PATTERN const, it's used as a pattern. # @return [Array<String>] the `csv` files of the target folder def target_files - @target_files ||= csv_files(options[:folder], regexp: file_pattern) + @target_files ||= [].then do + next options[:folder] if join_files + + csv_files(options[:folder], regexp: file_pattern) + end end # Deletes the files identified as target. def clear_files deleted_files = target_files.each_with_object([]) do |file, deleted| next unless File.exist?(file) + File.delete(file) deleted << file end + puts "Deleted these files:\n • #{deleted_files.join("\n • ")}" unless deleted_files.empty? end end end end