Sha256: 2ee0d7537404d52039ce7c5940f02cf65d7da5ad5c7750fabf809fe1652df202

Contents?: true

Size: 1.62 KB

Versions: 107

Compression:

Stored size: 1.62 KB

Contents

module RVM
  class Environment

    # Returns a hash of aliases.
    def alias_list
      lines = normalize_array(rvm(:alias, :list).stdout)
      lines.inject({}) do |acc, current|
        alias_name, ruby_string = current.to_s.split(" => ")
        unless alias_name.empty? || ruby_string.empty?
          acc[alias_name] = ruby_string
        end
        acc
      end
    end

    # Shows the full ruby string that a given alias points to.
    def alias_show(name)
      normalize rvm(:alias, :show, name.to_s).stdout
    end

    # Deletes an alias and returns the exit status.
    def alias_delete(name)
      rvm(:alias, :delete, name.to_s).successful?
    end

    # Creates an alias with the given name.
    def alias_create(name, ruby_string)
      rvm(:alias, :create, name.to_s, ruby_string.to_s).successful?
    end

    # Returns an aliases proxy which can be used in a more Ruby-like manner.
    def aliases
      @aliases ||= AliasWrapper.new(self)
    end

    # Provides a Ruby-like wrapper to the alias functionality.
    class AliasWrapper

      def initialize(parent)
        @parent = parent
      end

      # Shows the value of a given alias.
      def show(name)
        @parent.alias_show name
      end
      alias [] show

      # Deletes the given alias.
      def delete(name)
        @parent.alias_delete name
      end

      # Creates an alias with a given name and ruby string.
      def create(name, ruby_string)
        @parent.alias_create name, ruby_string
      end
      alias []= create

      # Returns a hash of all aliases.
      def list
        @parent.alias_list
      end
      alias all list

    end

  end
end

Version data entries

107 entries across 107 versions & 2 rubygems

Version Path
rvm-1.1.10 lib/rvm/environment/alias.rb
rvm-1.1.9 lib/rvm/environment/alias.rb
rvm-1.1.8 lib/rvm/environment/alias.rb
rvm-1.1.7 lib/rvm/environment/alias.rb
rvm-1.1.6 lib/rvm/environment/alias.rb
rvm-1.1.5 lib/rvm/environment/alias.rb
rvm-1.1.4 lib/rvm/environment/alias.rb
rvm-1.1.3 lib/rvm/environment/alias.rb
rvm-1.1.2 lib/rvm/environment/alias.rb
rvm-1.1.1 lib/rvm/environment/alias.rb
rvm-1.1.0 lib/rvm/environment/alias.rb
rvm-1.0.23 lib/rvm/environment/alias.rb
rvm-1.0.22 lib/rvm/environment/alias.rb
rvm-1.0.21 lib/rvm/environment/alias.rb
rvm-1.0.20 lib/rvm/environment/alias.rb
rvm-1.0.19 lib/rvm/environment/alias.rb
rvm-1.0.18 lib/rvm/environment/alias.rb
rvm-1.0.17 lib/rvm/environment/alias.rb
rvm-1.0.15 lib/rvm/environment/alias.rb
gemrage-1.0.0 vendor/ruby/1.8/gems/rvm-1.0.14/lib/rvm/environment/alias.rb