Sha256: 8130ce11c3227e50a28df0b07d6fa48e77b9e50c84a2aa1d8cc7a0f1719ecf55

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

class EcoRake
  module Lib
    module Files
      class Decrypt < EcoRake::Lib::BaseTask
        options_with_defaults true

        option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
        option '-l', '--list', TrueClass, desc: 'Lists available gpg feed files'
        option '-d', '--folder NAME', default: '.', desc: 'Source local folder'
        attr_const :ignore_mdc_error, default: false

        def task(*_args)
          return display_target_files if options[:list]
          return warn_missing_file    if target_files.empty?
          target_files.each do |file|
            delete_file(gpg_to_csv_filename(file))
            sh decrypt_command(file, ignore_mdc_error: ignore_mdc_error)
          end
          delete_file(*target_files, message: "Deleting files from '#{source_folder}'") unless options[:simulate]
        end

        def display_target_files
          puts "Source gpg files ('#{source_folder}'):"
          target_files.each {|file| puts "  • #{File.basename(file)}"}
        end

        def warn_missing_file
          puts "Could not find any file in folder '#{source_folder}'"
        end

        private

        # Amont the `target_files` the last in alphabetic order.
        def latest_file
          @latest_file ||= target_files.last
        end

        def target_files
          @target_files ||= gpg_files(source_folder)
        end

        def source_folder
          @source_folder ||= File.expand_path(options[:folder])
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eco-rake-0.1.1 lib/eco-rake/lib/files/decrypt.rb