Sha256: 52ce5286a88b690c412422da2e29d003972a622e0e52b693aff6c0427b05b8d6

Contents?: true

Size: 1.4 KB

Versions: 75

Compression:

Stored size: 1.4 KB

Contents

module RVM
  class Environment

    # Returns the contents of the env file.
    #
    # env.env_contents # => ['export PATH= ....', ...]
    #
    def env_contents
      rvm(:env, environment_name).stdout.split
    end

    # Returns the path to the env file
    # Suppose that you are in the 1.9.2 environment.
    #
    # env.env_path # => "~/.rvm/environments/ruby-1.9.2-p0"
    #
    def env_path
      normalize_array rvm(:env, environment_name, :path => true).stdout
    end

    # Returns a ruby-like wrapper for the env functions
    def env
      @env_wrapper ||= EnvWrapper.new(self)
    end

    # Returns the path for the given command
    #
    # Suppose that you are in the 1.9.2 environment.
    #
    # env.path_for(:rspec) # => '~/.rvm/gems/ruby-1.9.2-p0/bin/rspec'
    # env.path_for(:ruby)  # => '~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby'
    #
    def path_for(command)
      run(:command, "-v", command).stdout.strip
    end
    alias which path_for

    # Simple ruby like wrapper for envs.
    class EnvWrapper

      def initialize(parent)
        @parent = parent
      end

      # Contents of the env file.
      def contents
        @parent.env_contents
      end
      alias read contents
      alias to_s contents

      # The path of the env file.
      def path
        @parent.env_path
      end

      # Opens a file on the env file.
      def to_file
        File.open(path)
      end

    end

  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
rvm-1.11.3.9 lib/rvm/environment/env.rb
rvm-1.11.3.8 lib/rvm/environment/env.rb
rvm-1.11.3.7 lib/rvm/environment/env.rb
rvm-1.11.3.6 lib/rvm/environment/env.rb
rvm-1.11.3.5 lib/rvm/environment/env.rb
rvm-1.11.3.4 lib/rvm/environment/env.rb
rvm-1.11.3.3 lib/rvm/environment/env.rb
rvm-1.11.3.2 lib/rvm/environment/env.rb
rvm-1.11.3.1 lib/rvm/environment/env.rb
rvm-1.11.3 lib/rvm/environment/env.rb
rvm-1.9.2 lib/rvm/environment/env.rb
rvm-1.9.1 lib/rvm/environment/env.rb
rvm-1.9.0 lib/rvm/environment/env.rb
rvm-1.8.6 lib/rvm/environment/env.rb
rvm-1.8.5 lib/rvm/environment/env.rb
rvm-1.8.4 lib/rvm/environment/env.rb
rvm-1.8.3 lib/rvm/environment/env.rb
rvm-1.8.2 lib/rvm/environment/env.rb
rvm-1.8.1 lib/rvm/environment/env.rb
rvm-1.7.0 lib/rvm/environment/env.rb