Sha256: 9298ae8a987e31fb08e261b6b9a27b398058ef4a24eb1252ef3be1015c73ea5f

Contents?: true

Size: 1.24 KB

Versions: 11

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Mutant
  # The outer world IO objects mutant does interact with
  class World
    include Adamantium, Anima.new(
      :condition_variable,
      :gem,
      :gem_method,
      :io,
      :json,
      :kernel,
      :load_path,
      :marshal,
      :mutex,
      :object_space,
      :open3,
      :pathname,
      :process,
      :stderr,
      :stdout,
      :thread,
      :timer
    )

    INSPECT = '#<Mutant::World>'

    private_constant(*constants(false))

    # Object inspection
    #
    # @return [String]
    def inspect
      INSPECT
    end

    # Capture stdout of a command
    #
    # @param [Array<String>] command
    #
    # @return [Either<String,String>]
    def capture_stdout(command)
      stdout, status = open3.capture2(*command, binmode: true)

      if status.success?
        Either::Right.new(stdout)
      else
        Either::Left.new("Command #{command} failed!")
      end
    end

    # Deadline
    #
    # @param [Float, nil] allowed_time
    def deadline(allowed_time)
      if allowed_time
        Timer::Deadline.new(
          allowed_time: allowed_time,
          timer:        timer
        )
      else
        Timer::Deadline::None.new
      end
    end
  end # World
end # Mutant

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mutant-0.11.0 lib/mutant/world.rb
mutant-0.10.35 lib/mutant/world.rb
mutant-0.10.34 lib/mutant/world.rb
mutant-0.10.33 lib/mutant/world.rb
mutant-0.10.32 lib/mutant/world.rb
mutant-0.10.31 lib/mutant/world.rb
mutant-0.10.30 lib/mutant/world.rb
mutant-0.10.29 lib/mutant/world.rb
mutant-0.10.28 lib/mutant/world.rb
mutant-0.10.27 lib/mutant/world.rb
mutant-0.10.26 lib/mutant/world.rb