gem_tools 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-08-01
2
+
3
+ * Ported Rails plugin to a Gem:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Michael Moen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/PostInstall.txt ADDED
@@ -0,0 +1,2 @@
1
+
2
+ For more information on GemTools see http://github.com/UnderpantsGnome/gem_tools/wikis
data/README.txt ADDED
@@ -0,0 +1,97 @@
1
+ == GemTools
2
+
3
+ http://github.com/UnderpantsGnome/gem_tools-gem/wikis
4
+
5
+ === DESCRIPTION:
6
+
7
+ The gem verison of my lightweight tool to manage gems using a config file,
8
+ similar to GemInstaller.
9
+
10
+ === FEATURES/PROBLEMS:
11
+
12
+ Doesn't yet work in Windows
13
+
14
+ === SYNOPSIS:
15
+
16
+ I use this to manage gem versions in my apps, it has a rake task to install gems
17
+ and a load utility to load them on startup.
18
+
19
+ Install or update required gems
20
+ <pre><code>
21
+ gem_tools install
22
+ </pre></code>
23
+
24
+ Make sure they are loaded with the right versions during startup, by adding the
25
+ following to your script or environment.rb (Rails)
26
+ <pre><code>
27
+ require 'gem_tools'
28
+ GemTools.load_gems
29
+ </pre></code>
30
+
31
+ The config file looks like
32
+ <pre><code>
33
+ # These are optional
34
+ :source: http://local_mirror.example.com
35
+ gem_command: 'jruby -S gem'
36
+ :gems:
37
+ - :name: mongrel
38
+ :version: "1.0"
39
+ # this gem has a specfic source URL
40
+ :source: 'http://mongrel.rubyforge.org/releases'
41
+
42
+ - :name: hpricot_scrub
43
+ :version: '0.3.3'
44
+ # this tells us to load not just install
45
+ :load: true
46
+
47
+ - :name: postgres
48
+ :version: '0.7.1'
49
+ :load: true
50
+ # any extra config that needs to be passed to gem install
51
+ :config: '--with-pgsql-include-dir=/usr/local/pgsql/include
52
+ --with-pgsql-lib-dir=/usr/local/pgsql/lib'
53
+
54
+ - :name: rfeedparser_ictv
55
+ :version: '0.9.932'
56
+ :load: true
57
+ # this one has a different load name than the gem name (not a normal need)
58
+ :require_name: 'rfeedparser'
59
+ </pre></code>
60
+
61
+ === REQUIREMENTS:
62
+
63
+ None
64
+
65
+ === INSTALL:
66
+
67
+ sudo gem install gem_tools
68
+
69
+ === TODO
70
+
71
+ * Write the tests/specs
72
+ * Make it work in Windows
73
+
74
+ === LICENSE:
75
+
76
+ (The MIT License)
77
+
78
+ Copyright (c) 2008 Michael Moen
79
+
80
+ Permission is hereby granted, free of charge, to any person obtaining
81
+ a copy of this software and associated documentation files (the
82
+ 'Software'), to deal in the Software without restriction, including
83
+ without limitation the rights to use, copy, modify, merge, publish,
84
+ distribute, sublicense, and/or sell copies of the Software, and to
85
+ permit persons to whom the Software is furnished to do so, subject to
86
+ the following conditions:
87
+
88
+ The above copyright notice and this permission notice shall be
89
+ included in all copies or substantial portions of the Software.
90
+
91
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
92
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
93
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
94
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
95
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
96
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
97
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ module GemTools
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/gem_tools.rb ADDED
@@ -0,0 +1,110 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module GemTools
5
+ extend self
6
+
7
+ def run(cmd)
8
+ send(cmd.to_sym) rescue help
9
+ end
10
+
11
+ def load_gems
12
+ config = load_config
13
+ unless config['gems'].nil?
14
+ gems = config['gems'].reject {|gem_info| ! gem_info['load'] }
15
+ gems.each do |gem_info|
16
+ if defined?(Kernel::gem)
17
+ gem gem_info['name'], gem_info['version']
18
+ else
19
+ require_gem gem_info['name'], gem_info['version']
20
+ end
21
+ require gem_info['require_name'] || gem_info['name']
22
+ end
23
+ end
24
+ end
25
+
26
+ def help
27
+ puts OPTS
28
+ end
29
+
30
+ def load_config
31
+ require 'yaml'
32
+ require 'erb'
33
+ config_file = find_config
34
+ raise 'Could not find a gems.yml, checked . and ./config' unless File.exist?(config_file)
35
+ YAML.load(ERB.new(File.open(config_file).read).result)
36
+ end
37
+
38
+ def install
39
+ require 'rubygems'
40
+ if RUBY_PLATFORM =~ /MSWIN/
41
+ puts "gemtools install doesn't currently work in windows. The commands you need to install the gems will be printed out for you.\n"
42
+ dryrun
43
+ return
44
+ else
45
+ commands.each do |command|
46
+ ret = system command
47
+ # something bad happened, pass on the message
48
+ p $? unless ret
49
+ end
50
+ end
51
+ end
52
+
53
+ def dryrun
54
+ puts "\n#{commands.join("\n")}\n\n"
55
+ end
56
+
57
+ def commands
58
+ config = load_config
59
+ gems = config['gems']
60
+ commands = []
61
+
62
+ unless gems.nil?
63
+ docs = ''
64
+ unless OPTIONS.has_key?(:docs)
65
+ docs << '--no-rdoc ' unless (`rdoc -v`).nil?
66
+ docs << '--no-ri ' unless (`ri -v`).nil?
67
+ end
68
+
69
+ gem_command = config['gem_command'] || 'gem'
70
+ gem_dash_y = "1.0" > Gem::RubyGemsVersion ? '-y' : ''
71
+
72
+ gems.each do |gem|
73
+ spec, loaded, version = check_gem(gem['name'], gem['version'])
74
+ # if forced
75
+ # or the spec version doesn't match the required version
76
+ # or require_gem returns false
77
+ # (return false also happens if the gem has already been loaded)
78
+ if OPTIONS.has_key?(:force) || !spec || (! loaded && version != gem['version'])
79
+ gem_config = gem['config'] ? " -- #{gem['config']}" : ''
80
+ source = gem['source'] || config['source'] || nil
81
+ source = "--source #{source}" if source
82
+ cmd = "#{gem_command} install #{gem['path'] || gem['name']} -v #{gem['version']} #{gem_dash_y} #{source} #{docs} #{gem_config}"
83
+ commands << cmd
84
+ else
85
+ puts "#{gem['name']} #{gem['version']} already installed"
86
+ end
87
+ end
88
+ end
89
+ commands
90
+ end
91
+
92
+ def check_gem(name, version='')
93
+ spec = YAML.load(`gem spec #{name} 2> /dev/null`)
94
+ loaded = false
95
+ begin
96
+ loaded = require_gem name, version
97
+ version = spec.version.version
98
+ rescue Exception
99
+ end
100
+ [spec, loaded, version]
101
+ end
102
+
103
+ def find_config
104
+ %w( . config ).each do |dir|
105
+ config_file = File.join(dir, 'gems.yml')
106
+ return config_file if File.exist?(config_file)
107
+ end
108
+ end
109
+ end
110
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 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: 2008-08-06 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.0
24
+ version:
25
+ description: A lightweight tool to manage gems using a config file, similar to GemInstaller
26
+ email:
27
+ - michael@underpantsgnome.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - License.txt
35
+ - PostInstall.txt
36
+ - README.txt
37
+ files:
38
+ - History.txt
39
+ - License.txt
40
+ - PostInstall.txt
41
+ - README.txt
42
+ - lib/gem_tools.rb
43
+ - lib/gem_tools/version.rb
44
+ has_rdoc: true
45
+ homepage: http://underpantsgnome.rubyforge.org
46
+ post_install_message: |
47
+
48
+ For more information on GemTools see http://github.com/UnderpantsGnome/gem_tools/wikis
49
+
50
+ rdoc_options:
51
+ - --main
52
+ - README.txt
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project: underpantsgnome
70
+ rubygems_version: 1.2.0
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: A lightweight tool to manage gems using a config file, similar to GemInstaller
74
+ test_files: []
75
+