Sha256: ac5bcddd1d22089a72f1b51ee60a0232da8bc3b2c47630914b50c0990f81c0b5

Contents?: true

Size: 887 Bytes

Versions: 1

Compression:

Stored size: 887 Bytes

Contents

module LearnDoctor
  class HealthCheck
    class File
      attr_reader   :step, :check_or_install, :conn
      attr_accessor :file

      def initialize(step, check_or_install)
        @step             = step
        @check_or_install = check_or_install
        @conn             = Faraday.new

        prepare_file!

        return self
      end

      def unlink!
        self.file.unlink
      end

      def path
        file.path
      end

      private

      def prepare_file!
        create_file!
        write_to_file!
        make_executable!
      end

      def create_file!
        self.file = Tempfile.new(step[:title])
      end

      def write_to_file!
        response = conn.get(step[check_or_install])
        file.write(response.body)
        file.rewind
      end

      def make_executable!
        FileUtils.chmod('+x', file.path)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
learn-doctor-1.0.0 lib/learn_doctor/health_check/file.rb