Sha256: 9334ffbd5d90b1590ef2a0482029d62ddaa047c094ce1af2b90c25116fa3fd9b

Contents?: true

Size: 1.42 KB

Versions: 13

Compression:

Stored size: 1.42 KB

Contents

# typed: strict
# frozen_string_literal: true

require "fileutils"
require "open3"
require "time"
require "tmpdir"

require_relative "context/bundle"
require_relative "context/exec"
require_relative "context/file_system"
require_relative "context/git"
require_relative "context/sorbet"

module Spoom
  # An abstraction to a Ruby project context
  #
  # A context maps to a directory in the file system.
  # It is used to manipulate files and run commands in the context of this directory.
  class Context
    extend T::Sig

    include Bundle
    include Exec
    include FileSystem
    include Git
    include Sorbet

    class << self
      extend T::Sig

      # Create a new context in the system's temporary directory
      #
      # `name` is used as prefix to the temporary directory name.
      # The directory will be created if it doesn't exist.
      sig { params(name: T.nilable(String)).returns(T.attached_class) }
      def mktmp!(name = nil)
        new(::Dir.mktmpdir(name))
      end
    end

    # The absolute path to the directory this context is about
    sig { returns(String) }
    attr_reader :absolute_path

    # Create a new context about `absolute_path`
    #
    # The directory will not be created if it doesn't exist.
    # Call `#make!` to create it.
    sig { params(absolute_path: String).void }
    def initialize(absolute_path)
      @absolute_path = T.let(::File.expand_path(absolute_path), String)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spoom-1.5.0 lib/spoom/context.rb
spoom-1.4.2 lib/spoom/context.rb
spoom-1.4.1 lib/spoom/context.rb
spoom-1.4.0 lib/spoom/context.rb
spoom-1.3.3 lib/spoom/context.rb
spoom-1.3.2 lib/spoom/context.rb
spoom-1.3.1 lib/spoom/context.rb
spoom-1.3.0 lib/spoom/context.rb
spoom-1.2.4 lib/spoom/context.rb
spoom-1.2.3 lib/spoom/context.rb
spoom-1.2.2 lib/spoom/context.rb
spoom-1.2.1 lib/spoom/context.rb
spoom-1.2.0 lib/spoom/context.rb