Sha256: 902295987cb818ee07070124c8b2f786f7a427b90bb240aacd80c07c1ed189a5

Contents?: true

Size: 939 Bytes

Versions: 3

Compression:

Stored size: 939 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].gsub(' ', '_'))
      end

      def write_to_file!
        response = conn.get(step[check_or_install])
        file.write(response.body.sub('#!/bin/bash', '#!/bin/bash -l'))
        file.rewind
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
learn-doctor-1.0.3 lib/learn_doctor/health_check/file.rb
learn-doctor-1.0.2 lib/learn_doctor/health_check/file.rb
learn-doctor-1.0.1 lib/learn_doctor/health_check/file.rb