/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/version_option.rb

http://github.com/agross/netopenspace · Ruby · 65 lines · 38 code · 14 blank · 13 comment · 3 complexity · 56abc76282d4d5a0194916d48a58416f MD5 · raw file

  1. #--
  2. # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
  3. # All rights reserved.
  4. # See LICENSE.txt for permissions.
  5. #++
  6. require 'rubygems'
  7. ##
  8. # Mixin methods for --version and --platform Gem::Command options.
  9. module Gem::VersionOption
  10. ##
  11. # Add the --platform option to the option parser.
  12. def add_platform_option(task = command, *wrap)
  13. OptionParser.accept Gem::Platform do |value|
  14. if value == Gem::Platform::RUBY then
  15. value
  16. else
  17. Gem::Platform.new value
  18. end
  19. end
  20. add_option('--platform PLATFORM', Gem::Platform,
  21. "Specify the platform of gem to #{task}", *wrap) do
  22. |value, options|
  23. unless options[:added_platform] then
  24. Gem.platforms = [Gem::Platform::RUBY]
  25. options[:added_platform] = true
  26. end
  27. Gem.platforms << value unless Gem.platforms.include? value
  28. end
  29. end
  30. ##
  31. # Add the --prerelease option to the option parser.
  32. def add_prerelease_option(*wrap)
  33. add_option("--[no-]prerelease",
  34. "Allow prerelease versions of a gem", *wrap) do |value, options|
  35. options[:prerelease] = value
  36. end
  37. end
  38. ##
  39. # Add the --version option to the option parser.
  40. def add_version_option(task = command, *wrap)
  41. OptionParser.accept Gem::Requirement do |value|
  42. Gem::Requirement.new value
  43. end
  44. add_option('-v', '--version VERSION', Gem::Requirement,
  45. "Specify version of gem to #{task}", *wrap) do
  46. |value, options|
  47. options[:version] = value
  48. options[:prerelease] = true if value.prerelease?
  49. end
  50. end
  51. end