Sha256: 19b6f9de24c4f99c2fea8311bf9a208c40fcb7301f19a232ca2e0839cc074220

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 KB

Contents

module Steep
  module Drivers
    module Utils
      module DriverHelper
        attr_accessor :steepfile

        def load_config(path: steepfile || Pathname("Steepfile"))
          raise "Cannot find a configuration at #{path}: `steep init` to scaffold" unless path.file?

          steep_file_path = path.absolute? ? path : Pathname.pwd + path
          Project.new(steepfile_path: steep_file_path).tap do |project|
            Project::DSL.parse(project, path.read, filename: path.to_s)
          end
        end

        def type_check(project)
          project.targets.each do |target|
            Steep.logger.tagged "target=#{target.name}" do
              target.type_check
            end
          end
        end

        def request_id
          SecureRandom.alphanumeric(10)
        end

        def wait_for_response_id(reader:, id:, unknown_responses: :ignore)
          wait_for_message(reader: reader, unknown_messages: unknown_responses) do |response|
            response[:id] == id
          end
        end

        def shutdown_exit(writer:, reader:)
          request_id().tap do |id|
            writer.write({ method: :shutdown, id: id })
            wait_for_response_id(reader: reader, id: id)
          end
          writer.write({ method: :exit })
        end

        def wait_for_message(reader:, unknown_messages: :ignore, &block)
          reader.read do |message|
            if yield(message)
              return message
            else
              case unknown_messages
              when :ignore
                # nop
              when :log
                Steep.logger.error { "Unexpected message: #{message.inspect}" }
              when :raise
                raise "Unexpected message: #{message.inspect}"
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
steep-0.45.0 lib/steep/drivers/utils/driver_helper.rb
steep-0.44.1 lib/steep/drivers/utils/driver_helper.rb
steep-0.44.0 lib/steep/drivers/utils/driver_helper.rb
steep-0.43.1 lib/steep/drivers/utils/driver_helper.rb
steep-0.43.0 lib/steep/drivers/utils/driver_helper.rb