Sha256: d767efa626e75dffa8616640b270539761405477643abcc5e475af3512d58fa0

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

# frozen_string_literal: true

module Shellject
  module Tasks
    # Loads, decrypts, and outputs a shelljection
    class Load
      include CryptoTask
      attr_reader :save_directory, :name

      def initialize(save_directory, name)
        @save_directory = save_directory
        @name = name
      end

      def call
        ensure_readable
        file = File.open path
        STDOUT.print crypto.decrypt(file)
      ensure
        file&.close
      end

      private

      def ensure_readable
        raise ShelljectError, "Could not read file #{path}" unless readable?
      end

      def readable?
        path.readable?
      end

      def path
        @path ||= save_directory.path_for name
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shellject-1.0.2 lib/shellject/tasks/load.rb