Skip to content

Commit

Permalink
fixed alias behavior, trying to create an existing alias overwrites t…
Browse files Browse the repository at this point in the history
…he old alias, fixed spelling error
  • Loading branch information
vertiginous committed Mar 3, 2011
1 parent 178e066 commit 40746bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/pik/commands/alias_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ def execute
end
end

def create(pseudonum, name)
def create(pseudonym, name)
if version = config.find_pattern(name)
config[version.first][:alias] = pseudonum
config.create_alias(version.first, pseudonym)
else
Log.error "Ruby version not found."
end
end

def delete(pseudonum)
if version = config.find_alias(pseudonum)
def delete(pseudonym)
if version = config.find_alias(pseudonym)
config[version.first].delete(:alias)
else
Log.error "Ruby version '#{pseudonum}' not found."
Log.error "Ruby version '#{pseudonym}' not found."
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pik/commands/use_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def execute

ver_name, ver_config = *new_ver

ver_config[:alias] = 'default' if default
config.create_alias(ver_name,'default') if default

switch_path_to(ver_config)
switch_gem_home_to(ver_config[:gem_home])
Expand Down
5 changes: 5 additions & 0 deletions lib/pik/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def initialize(file = File.join(Pik.home, 'config.yml'))
def_delegators :@rubies, :[], :[]=, :clear, :sort, :find, :keys,
:delete, :each, :include?, :select

def create_alias(key, alias_name)
each{|name,data| data.delete_if{|k,v| k == :alias && v == alias_name }}
self[key][:alias] = alias_name
end

def match(string)
find do |pattern, ver|
VersionPattern.parse(pattern).include?(string) || ver[:alias] == string
Expand Down

0 comments on commit 40746bf

Please sign in to comment.