markbates-gem_tools 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ README
2
+ ========================================================================
3
+ gem_tools was developed by: markbates
data/lib/gem_tools.rb ADDED
@@ -0,0 +1,3 @@
1
+ Dir.glob(File.join(File.dirname(__FILE__), 'gem_tools', '**/*.rb')).each do |f|
2
+ require File.expand_path(f)
3
+ end
@@ -0,0 +1,135 @@
1
+ require 'yamler'
2
+ $:.unshift(File.dirname(__FILE__)) unless
3
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
4
+
5
+ module GemTools
6
+ extend self
7
+
8
+ def run(cmd)
9
+ send(cmd.to_sym)# rescue help
10
+ end
11
+
12
+ def setup
13
+ require 'fileutils'
14
+ dest_file = File.join(ARGV[1], '/config/gems.yml')
15
+ if File.exist?(dest_file) && ! OPTIONS.has_key?(:force)
16
+ puts "#{dest_file} already exists.\n\ngemtools install #{ARGV[1]} --force\n\nto overwrite"
17
+ exit 1
18
+ else
19
+ FileUtils.copy(File.join(File.dirname(__FILE__), '../config/gems.template.yml'), dest_file)
20
+ puts "#{dest_file} created"
21
+ end
22
+ end
23
+
24
+ def help
25
+ puts OPTIONS
26
+ end
27
+
28
+ def install
29
+ require 'rubygems'
30
+ if RUBY_PLATFORM =~ /MSWIN/
31
+ puts "gemtools install doesn't currently work in windows. The commands you need to install the gems will be printed out for you.\n"
32
+ dryrun
33
+ return
34
+ else
35
+ commands.each do |command|
36
+ ret = system command
37
+ # something bad happened, pass on the message
38
+ p $? unless ret
39
+ end
40
+ end
41
+ end
42
+
43
+ def dryrun
44
+ puts "\n#{commands.join("\n")}\n\n"
45
+ end
46
+
47
+ def commands
48
+ config = load_config
49
+ gems = config['gems']
50
+ commands = []
51
+
52
+ unless gems.nil?
53
+ docs = ''
54
+ unless OPTIONS.has_key?(:docs)
55
+ docs << '--no-rdoc ' unless (`rdoc -v`).nil?
56
+ docs << '--no-ri ' unless (`ri -v`).nil?
57
+ end
58
+
59
+ gem_command = config['gem_command'] || 'gem'
60
+ gem_dash_y = "1.0" > Gem::RubyGemsVersion ? '-y' : ''
61
+
62
+ gems.each do |gem|
63
+ spec, loaded, version = check_gem(gem_command, gem['name'], gem['version'])
64
+ # if forced
65
+ # or the spec version doesn't match the required version
66
+ # or require_gem returns false
67
+ # (return false also happens if the gem has already been loaded)
68
+ if OPTIONS.has_key?(:force) || !spec || (! loaded && version != gem['version'])
69
+ gem_config = gem['config'] ? " -- #{gem['config']}" : ''
70
+ source = gem['source'] || config['source'] || nil
71
+ source = "--source #{source}" if source
72
+ cmd = "#{gem_command} install #{gem['path'] || gem['name']} -v '#{gem['version']}' #{gem_dash_y} #{source} #{docs} #{gem_config}"
73
+ commands << cmd
74
+ else
75
+ puts "#{gem['name']} #{gem['version']} already installed"
76
+ end
77
+ end
78
+ end
79
+ commands
80
+ end
81
+
82
+ def check_gem(command, name, version='')
83
+ spec = YAML.load(`#{command} spec #{name} 2> /dev/null`)
84
+ loaded = false
85
+ begin
86
+ loaded = require_gem name, version
87
+ version = spec.version.version
88
+ rescue Exception
89
+ end
90
+ [spec, loaded, version]
91
+ end
92
+
93
+ def load_gems
94
+ config = load_config
95
+ unless config['gems'].nil?
96
+ gems = config['gems'].reject {|gem_info| ! gem_info['load'] }
97
+ gems.each do |gem_info|
98
+ if defined?(gem)
99
+ gem gem_info['name'], gem_info['version']
100
+ else
101
+ require_gem gem_info['name'], gem_info['version']
102
+ end
103
+ reqs = [(gem_info['require_name'] || gem_info['name'])].flatten
104
+ reqs.each do |req|
105
+ require req
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ def load_config
112
+ config_file = find_config
113
+ unless config_file
114
+ puts 'Could not find a gems.yml, checked . and ./config'
115
+ exit 1
116
+ end
117
+ Yamler.load(config_file)
118
+ end
119
+
120
+ def find_config
121
+ dirs = []
122
+ if Object.const_defined?('RAILS_ROOT')
123
+ dirs << RAILS_ROOT
124
+ dirs << File.join(RAILS_ROOT, 'config')
125
+ end
126
+ dirs << %w{. config}
127
+ dirs.flatten!
128
+
129
+ dirs.each do |dir|
130
+ config_file = File.join(dir, 'gems.yml')
131
+ return config_file if File.exist?(config_file)
132
+ end
133
+ nil
134
+ end
135
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markbates-gem_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Moen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-02 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: markbates-yamler
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.4
23
+ version:
24
+ description: A lightweight tool to manage gems using a config file, similar to GemInstaller
25
+ email: michael@underpantsgnome.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ files:
33
+ - lib/gem_tools/gem_tools.rb
34
+ - lib/gem_tools.rb
35
+ - README
36
+ has_rdoc: true
37
+ homepage: http://underpantsgnome.rubyforge.org
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project: underpantsgnome
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A lightweight tool to manage gems using a config file, similar to GemInstaller
62
+ test_files: []
63
+