Skip to content

Commit

Permalink
Spring cleaning in helpers removing old methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnichol committed Aug 9, 2011
1 parent 9a17648 commit b434934
Showing 1 changed file with 1 addition and 83 deletions.
84 changes: 1 addition & 83 deletions libraries/chef_rvm_helpers.rb
Expand Up @@ -43,7 +43,7 @@ def select_ruby(ruby_string)
# @param [String, #to_s] the fully qualified RVM ruby string
# @return [String] the gemset string, minus ruby or nil if no gemset given
def select_gemset(ruby_string)
if string_include_gemset?(ruby_string)
if ruby_string.include?('@')
ruby_string.split('@').last
else
nil
Expand All @@ -59,30 +59,9 @@ def normalize_ruby_string(ruby_string)
return "system" if ruby_string == "system"
StringCache[ruby_string]
end

private

##
# Determines whether or not there is a gemset defined in a given ruby string
#
# @param [String, #to_s] the fully qualified RVM ruby string
# @return [Boolean] does the ruby string appear to have a gemset included?
def string_include_gemset?(ruby_string)
ruby_string.include?('@')
end
end

module RubyHelpers
##
# Determines if given ruby string is moderatley sane and potentially legal
#
# @param [String, #to_s] the fully qualified RVM ruby string
# @return [Boolean] is this ruby string sane?
def ruby_string_sane?(rubie)
return true if ['goruby', 'ree', 'kiji'].include?(rubie) # rubies with aliases
return true if rubie =~ /^[^-]+-[^-]+/ # must be xxx-vvv at least
end

##
# Lists all installed RVM rubies on the system.
#
Expand All @@ -109,70 +88,9 @@ def update_installed_rubies
# @param [String, #to_s] the fully qualified RVM ruby string
# @return [Boolean] is this ruby installed?
def ruby_installed?(rubie)
return false unless ruby_string_sane?(rubie)

! installed_rubies.select { |r| r.start_with?(rubie) }.empty?
end

##
# Inverse of #ruby_installed?
#
# @param [String, #to_s] the fully qualified RVM ruby string
# @return [Boolean] is this ruby not installed?
def ruby_not_installed?(rubie)
!ruby_installed?(rubie)
end

##
# Determines whether or not the given ruby is a known ruby string
#
# @param [String, #to_s] the fully qualified RVM ruby string
# @return [Boolean] is this ruby in the known ruby string list?
def ruby_known?(rubie)
return true if rubie == 'system'
return false unless ruby_string_sane?(rubie)

matches = known_rubies.select { |r| r.start_with?(rubie) }
if matches.empty?
# last-ditch attempt at matching. we'll drop the last -.*$ bit off the
# string assuming that the rubie contains a non-default patchlevel that
# will actually exist
fuzzier_rubie = rubie.sub(/-[^-]+$/, '')
return ! known_rubies.select { |r| r.start_with?(fuzzier_rubie) }.empty?
else
return true
end
end

##
# List all known RVM ruby strings.
#
# **Note** that these values are cached for lookup speed. To flush these
# values and force an update, call #update_known_rubies.
#
# @return [Array] the cached list of known ruby strings
def known_rubies
@known_rubies ||= update_known_rubies
end

##
# Updates the list of all known RVM strings.
#
# @return [Array] the list of known ruby strings
def update_known_rubies
@known_rubies = ::RVM.list_known_strings
@known_rubies
end

##
# Inverse of #ruby_known?
#
# @param [String, #to_s] the fully qualified RVM ruby string
# @return [Boolean] is this ruby an unknown ruby string?
def ruby_unknown?(rubie)
!ruby_known?(rubie)
end

##
# Fetches the current default ruby string, potentially with gemset
#
Expand Down

0 comments on commit b434934

Please sign in to comment.