Module: GemTools
Instance Method Summary collapse
- #check_gem(command, name, version = '') ⇒ Object
- #commands ⇒ Object
- #dryrun ⇒ Object
- #find_config ⇒ Object
- #help ⇒ Object
- #install ⇒ Object
- #load_config ⇒ Object
- #load_gems ⇒ Object
- #run(cmd) ⇒ Object
- #setup ⇒ Object
Instance Method Details
#check_gem(command, name, version = '') ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/gem_tools/gem_tools.rb', line 81 def check_gem(command, name, version='') begin return gem(name, version) rescue Exception => e end return false end |
#commands ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gem_tools/gem_tools.rb', line 47 def commands config = load_config gems = config['gems'] commands = [] unless gems.nil? docs = '' unless OPTIONS.has_key?(:docs) docs << '--no-rdoc ' unless (`rdoc -v`).nil? docs << '--no-ri ' unless (`ri -v`).nil? end gem_command = config['gem_command'] || 'gem' gem_dash_y = "1.0" > Gem::RubyGemsVersion ? '-y' : '' gems.each do |gem| # if forced # or the spec version doesn't match the required version # or require_gem returns false # (return false also happens if the gem has already been loaded) if OPTIONS.has_key?(:force) || !check_gem(gem_command, gem['name'], gem['version']) gem_config = gem['config'] ? " -- #{gem['config']}" : '' source = gem['source'] || config['source'] || nil source = "--source #{source}" if source cmd = "#{gem_command} install #{gem['path'] || gem['name']} -v '#{gem['version']}' #{gem_dash_y} #{source} #{docs} #{gem_config}" commands << cmd else puts "#{gem['name']} #{gem['version']} already installed" end end end commands end |
#dryrun ⇒ Object
43 44 45 |
# File 'lib/gem_tools/gem_tools.rb', line 43 def dryrun puts "\n#{commands.join("\n")}\n\n" end |
#find_config ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gem_tools/gem_tools.rb', line 116 def find_config dirs = [] if Object.const_defined?('RAILS_ROOT') dirs << RAILS_ROOT dirs << File.join(RAILS_ROOT, 'config') end dirs << %w{. config} dirs.flatten! dirs.each do |dir| config_file = File.join(dir, 'gems.yml') return config_file if File.exist?(config_file) end nil end |
#help ⇒ Object
24 25 26 |
# File 'lib/gem_tools/gem_tools.rb', line 24 def help puts OPTIONS end |
#install ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gem_tools/gem_tools.rb', line 28 def install require 'rubygems' if RUBY_PLATFORM =~ /MSWIN/ puts "gemtools install doesn't currently work in windows. The commands you need to install the gems will be printed out for you.\n" dryrun return else commands.each do |command| ret = system command # something bad happened, pass on the message p $? unless ret end end end |
#load_config ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/gem_tools/gem_tools.rb', line 107 def load_config config_file = find_config unless config_file puts 'Could not find a gems.yml, checked . and ./config' exit 1 end Yamler.load(config_file) end |
#load_gems ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gem_tools/gem_tools.rb', line 89 def load_gems config = load_config unless config['gems'].nil? gems = config['gems'].reject {|gem_info| ! gem_info['load'] } gems.each do |gem_info| if defined?(gem) gem gem_info['name'], gem_info['version'] else require_gem gem_info['name'], gem_info['version'] end reqs = [(gem_info['require_name'] || gem_info['name'])].flatten reqs.each do |req| require req end end end end |
#run(cmd) ⇒ Object
8 9 10 |
# File 'lib/gem_tools/gem_tools.rb', line 8 def run(cmd) send(cmd.to_sym)# rescue help end |
#setup ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gem_tools/gem_tools.rb', line 12 def setup require 'fileutils' dest_file = File.join(ARGV[1], '/config/gems.yml') if File.exist?(dest_file) && ! OPTIONS.has_key?(:force) puts "#{dest_file} already exists.\n\ngemtools install #{ARGV[1]} --force\n\nto overwrite" exit 1 else FileUtils.copy(File.join(File.dirname(__FILE__), '../config/gems.template.yml'), dest_file) puts "#{dest_file} created" end end |