Guest User

Untitled

a guest
Feb 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. require 'capistrano'
  2. # Installs within Capistrano as the plugin _gem_.
  3. # Prefix all calls to the library with <tt>gem.</tt>
  4. # Manages installing gems and versioned gems.
  5. module GemInstaller
  6.  
  7. # Default install command
  8. #
  9. # * doesn't install documentation
  10. # * installs all required dependencies automatically.
  11. #
  12. GEM_INSTALL="gem install -y --no-rdoc --no-ri"
  13.  
  14. # Upgrade the *gem* system to the latest version. Runs via *sudo*
  15. def update_system
  16. sudo "gem update --system"
  17. end
  18.  
  19. # Updates all the installed gems to the latest version. Runs via *sudo*.
  20. # Don't use this command if any of the gems require a version selection.
  21. def upgrade
  22. sudo "gem update --no-rdoc"
  23. end
  24.  
  25. # Removes old versions of gems from installation area.
  26. def cleanup
  27. sudo "gem cleanup"
  28. end
  29.  
  30. # Installs the gems detailed in +packages+, selecting version +version+ if
  31. # specified.
  32. #
  33. # +packages+ can be a single string or an array of strings.
  34. #
  35. def install(packages, version=nil)
  36. sudo "#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{packages.to_a.join(' ')}"
  37. end
  38.  
  39. # Auto selects a gem from a list and installs it.
  40. #
  41. # *gem* has no mechanism on the command line of disambiguating builds for
  42. # different platforms, and instead asks the user. This method has the necessary
  43. # conversation to select the +version+ relevant to +platform+ (or the one nearest
  44. # the top of the list if you don't specify +version+).
  45. def select(package, version=nil, platform='ruby')
  46. selections={}
  47. cmd="#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{package}"
  48. sudo cmd do |channel, stream, data|
  49. data.each_line do | line |
  50. case line
  51. when /\s(\d+).*\(#{platform}\)/
  52. if selections[channel[:host]].nil?
  53. selections[channel[:host]]=$1.dup+"\n"
  54. logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}"
  55. end
  56. when /\s\d+\./
  57. # Discard other selections from data stream
  58. when /^>/
  59. channel.send_data selections[channel[:host]]
  60. logger.debug line, "#{stream} :: #{channel[:host]}"
  61. else
  62. logger.info line, "#{stream} :: #{channel[:host]}"
  63. end
  64. end
  65. end
  66. end
  67.  
  68. end
  69.  
  70. Capistrano.plugin :gem, GemInstaller
Add Comment
Please, Sign In to add comment