Class: ChickenLittle::Patch
- Inherits:
-
Object
- Object
- ChickenLittle::Patch
- Extended by:
- Commandable
- Defined in:
- lib/chicken_little/patch.rb
Instance Method Summary collapse
- #describe_fix(force_description = true) ⇒ Object
- #fix_gems ⇒ Object
- #force_install ⇒ Object
- #install ⇒ Object
- #installed? ⇒ Boolean
- #supported? ⇒ Boolean
- #uninstall ⇒ Object
Instance Method Details
#describe_fix(force_description = true) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/chicken_little/patch.rb', line 108 def describe_fix(force_description=true) flag_file = "#{File.(File.dirname(__FILE__))}/better_fix_described" unless File.exist?(flag_file) && !force_description FileUtils.touch flag_file puts %{ Important! The old install method should not be necessary. A better fix is to run: $ gem pristine --all --no-extensions Then run this: $ gem pristine --all You may need to run those commands several times. If you still have problems you can then force the old install method with: $ chicken_little force_install} end end |
#fix_gems ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/chicken_little/patch.rb', line 50 def fix_gems (1..5).each do |i| puts "Run ##{i}: Cleaning up gems, this may take a while." output = capture_output{ Gem::GemRunner.new.run %w{list} } break if output[:stderr].empty? output = capture_output{ case i when 1,4 Gem::GemRunner.new.run %w{pristine --all --no-extensions} else Gem::GemRunner.new.run %w{pristine --all} end } end end |
#force_install ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chicken_little/patch.rb', line 68 def force_install describe_fix supported? return "Chicken Little is already installed" if installed? new_spec_file = spec_file_contents.collect { |line| line.index(Uncommented_Line) ? "##{line.strip}\n" : line} save_spec_file(new_spec_file) if installed? "Chicken Little installed successfully." else "Install failed. No idea why." end end |
#install ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chicken_little/patch.rb', line 13 def install describe_fix false puts %{ Chicken Little is attempting to fix the errors for you properly. This may take a while. The fix will be run repeatedly until the errors go away or it's tried too many times. } # Test for RVM begin puts "Fixing the global RVM gemset first" #ruby_ver, gemset = `rvm-prompt`.strip.split("@") rvm_path = File.(ENV['rvm_path'] || '~/.rvm') $LOAD_PATH.unshift File.join(rvm_path, 'lib') require 'rvm' current_env = RVM.current.environment_name #puts "Current: #{current_env.inspect}" # puts `rvm-prompt` rvm = RVM.environment current_env rvm.gemset_use! 'global' # puts `rvm-prompt` fix_gems rvm.use! "#{current_env}" # puts `rvm-prompt` puts "RVM global gemset done" rescue Exception #skipping error puts "RVM not found" end puts "\nFixing your default gemset now" fix_gems puts "All done. Enjoy" end |
#installed? ⇒ Boolean
95 96 97 |
# File 'lib/chicken_little/patch.rb', line 95 def installed? !spec_file_contents.select { |line| line.strip.start_with?("##{Uncommented_Line}") }.empty? end |
#supported? ⇒ Boolean
100 101 102 103 104 105 |
# File 'lib/chicken_little/patch.rb', line 100 def supported? raise ChickenLittle::GemFileNotFound unless gem_file_found? raise ChickenLittle::SpecFileNotFound unless spec_file_found? raise ChickenLittle::SpecFileNotWritable unless spec_file_writable? "Looks good. Chicken Little can find and modify the necessary files." end |
#uninstall ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/chicken_little/patch.rb', line 82 def uninstall supported? return "Chicken Little isn't installed" unless installed? new_spec_file = spec_file_contents.collect { |line| line.index(Uncommented_Line) ? line.delete("#") : line} save_spec_file(new_spec_file) unless installed? "Chicken Little uninstalled successfully." else "Uninstall failed. No idea why." end end |