Sha256: f2a3d70c3944400d43f51c1b297c3774fde8a7f371b15a1f631e1246334f9a86

Contents?: true

Size: 1.26 KB

Versions: 17

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

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

    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

17 entries across 17 versions & 1 rubygems

Version Path
mutant-0.10.23 lib/mutant/world.rb
mutant-0.10.22 lib/mutant/world.rb
mutant-0.10.21 lib/mutant/world.rb
mutant-0.10.20 lib/mutant/world.rb
mutant-0.10.19 lib/mutant/world.rb
mutant-0.10.18 lib/mutant/world.rb
mutant-0.10.17 lib/mutant/world.rb
mutant-0.10.16 lib/mutant/world.rb
mutant-0.10.15 lib/mutant/world.rb
mutant-0.10.14 lib/mutant/world.rb
mutant-0.10.13 lib/mutant/world.rb
mutant-0.10.12 lib/mutant/world.rb
mutant-0.10.11 lib/mutant/world.rb
mutant-0.10.10 lib/mutant/world.rb
mutant-0.10.9 lib/mutant/world.rb
mutant-0.10.8 lib/mutant/world.rb
mutant-0.10.7 lib/mutant/world.rb