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.6.32 lib/rvm/environment/env.rb
rvm-1.6.31 lib/rvm/environment/env.rb
rvm-1.6.30 lib/rvm/environment/env.rb
rvm-1.6.29 lib/rvm/environment/env.rb
rvm-1.6.27 lib/rvm/environment/env.rb
rvm-1.6.24 lib/rvm/environment/env.rb
rvm-1.6.23 lib/rvm/environment/env.rb
rvm-1.6.22 lib/rvm/environment/env.rb
rvm-1.6.21 lib/rvm/environment/env.rb
rvm-1.6.20 lib/rvm/environment/env.rb
rvm-1.6.19 lib/rvm/environment/env.rb
rvm-1.6.16 lib/rvm/environment/env.rb
rvm-1.6.13 lib/rvm/environment/env.rb
rvm-1.6.12 lib/rvm/environment/env.rb
rvm-1.6.11 lib/rvm/environment/env.rb
rvm-1.6.10 lib/rvm/environment/env.rb
rvm-1.6.9 lib/rvm/environment/env.rb
rvm-1.6.8 lib/rvm/environment/env.rb
rvm-1.6.7 lib/rvm/environment/env.rb
rvm-1.6.6 lib/rvm/environment/env.rb