kelredd-gemsconfig 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +106 -0
- data/Rakefile +40 -0
- data/lib/gemsconfig.rb +31 -0
- data/lib/gemsconfig/config.rb +18 -0
- data/lib/gemsconfig/entry.rb +68 -0
- data/lib/gemsconfig/tasks/cap.rb +1 -0
- data/lib/gemsconfig/tasks/rake.rb +10 -0
- data/lib/gemsconfig/version.rb +13 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/gemsconfig_test.rb +13 -0
- metadata +66 -0
data/README.rdoc
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
= Gemsconfig
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
A gem to manage gem configuration for a project, similar to Rails' config.gem (but in a very simple, dumb way)
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
sudo gem install kelredd-gemsconfig --source http://gems.github.com
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
(in any main project ruby file that is loaded on project start)
|
13
|
+
require 'rubygems'
|
14
|
+
require 'config/gems.rb' # custom Gemsconfig configuration for your project
|
15
|
+
Gemsconfig::load
|
16
|
+
|
17
|
+
The file 'config/gems.rb' should require in 'gemsconfig', call Gemsconfig::init, and specify the gem
|
18
|
+
configurations (see example in 'Configuration' below). Gemsconfig::load will attempt to load each
|
19
|
+
gem configured. Any load errors will be thrown and alerted.
|
20
|
+
|
21
|
+
== Rake Usage
|
22
|
+
Gemsconfig comes with a rake task that will attempt to install any gems not yet installed. To use it, be sure to install
|
23
|
+
rake and have a Rakefile that contains something like this:
|
24
|
+
|
25
|
+
# Rakefile example
|
26
|
+
require 'rubygems'
|
27
|
+
require 'config/gems.rb' # custom Gemsconfig configuration for your project
|
28
|
+
require 'gemsconfig/tasks/rake'
|
29
|
+
|
30
|
+
Now to use the install task:
|
31
|
+
|
32
|
+
(in terminal)
|
33
|
+
rake -T # make sure gemsconfig:install task is loaded and available
|
34
|
+
rake gemsconfig:install # attemp to install any gems not yet installed
|
35
|
+
|
36
|
+
== Capistrano Usage
|
37
|
+
|
38
|
+
So it would be really awesome to have a cap task like 'cap deploy:gems' that would do a capistrano deploy and run 'rake gemsconfig:install'
|
39
|
+
as part of said deploy. I'll add this someday...
|
40
|
+
|
41
|
+
== Configuration
|
42
|
+
|
43
|
+
Gemsconfig expects to be initialized with configuration entries for each gem that needs to be configured for your project. This
|
44
|
+
initialization is typically done in a configuration file that is required in to the main app file. Here's an example:
|
45
|
+
|
46
|
+
# gems.rb example
|
47
|
+
require 'gemsconfig'
|
48
|
+
|
49
|
+
Gemsconfig::init do |config|
|
50
|
+
config.gem 'sinatra'
|
51
|
+
|
52
|
+
config.gem 'kelredd-useful',
|
53
|
+
:lib => 'useful/ruby_extensions',
|
54
|
+
:source => 'http://gems.github.com'
|
55
|
+
|
56
|
+
config.gem 'kelredd-useful',
|
57
|
+
:lib => 'useful/sinatra_helpers',
|
58
|
+
:source => 'http://gems.github.com'
|
59
|
+
|
60
|
+
config.gem 'kelredd-activerecord-sinatra',
|
61
|
+
:lib => 'activerecord_sinatra',
|
62
|
+
:source => 'http://gems.github.com'
|
63
|
+
|
64
|
+
config.gem 'kelredd-sprockets-sinatra',
|
65
|
+
:lib => 'sprockets_sinatra',
|
66
|
+
:version => '0.2.1',
|
67
|
+
:source => 'http://gems.github.com'
|
68
|
+
|
69
|
+
config.gem 'kelredd-repository',
|
70
|
+
:lib => 'repository/filesystem',
|
71
|
+
:source => 'http://gems.github.com'
|
72
|
+
end
|
73
|
+
|
74
|
+
== Gotchas
|
75
|
+
|
76
|
+
* Sinatra: I would be careful configuring the Sinatra gem using Gemsconfig. Sinatra expects to be required in the main app.rb
|
77
|
+
file. If you only configure the sinatra gem in your Gemsconfig, it gets required from one of Gemsconfig's lib files and
|
78
|
+
this messes up the Sinatra::Application.root variable (among other things I'm sure). A best practice would be to go ahead
|
79
|
+
and configure sinatra in Gemsconfig (as in the example above), AND require it in your main app.rb file BEFORE requiring your
|
80
|
+
Gemsconfig. This way sinatra gets required like it expects, and when Gemsconfig attempts to require it, nothing will happen,
|
81
|
+
and you still get the rake task benefit from having Sinatra in the Gemsconfig.
|
82
|
+
|
83
|
+
== License
|
84
|
+
|
85
|
+
Copyright (c) 2009 Kelly Redding
|
86
|
+
|
87
|
+
Permission is hereby granted, free of charge, to any person
|
88
|
+
obtaining a copy of this software and associated documentation
|
89
|
+
files (the "Software"), to deal in the Software without
|
90
|
+
restriction, including without limitation the rights to use,
|
91
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
92
|
+
copies of the Software, and to permit persons to whom the
|
93
|
+
Software is furnished to do so, subject to the following
|
94
|
+
conditions:
|
95
|
+
|
96
|
+
The above copyright notice and this permission notice shall be
|
97
|
+
included in all copies or substantial portions of the Software.
|
98
|
+
|
99
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
100
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
101
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
102
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
103
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
104
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
105
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
106
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
require 'lib/gemsconfig/version'
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
spec = Gem::Specification.new do |s|
|
10
|
+
s.name = 'gemsconfig'
|
11
|
+
s.version = Gemsconfig::Version.to_s
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
14
|
+
s.rdoc_options = %w(--main README.rdoc)
|
15
|
+
s.summary = "A gem to manage gem configuration for a project, similar to Rails' config.gem (but in a very simple, dumb way)"
|
16
|
+
s.author = 'Kelly Redding'
|
17
|
+
s.email = 'kelly@kelredd.com'
|
18
|
+
s.homepage = ''
|
19
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
20
|
+
# s.executables = ['gemsconfig']
|
21
|
+
|
22
|
+
# s.add_dependency('gem_name', '~> 0.0.1')
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
26
|
+
pkg.gem_spec = spec
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::TestTask.new do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
32
|
+
t.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Generate the gemspec to serve this Gem from Github'
|
36
|
+
task :github do
|
37
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
38
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
39
|
+
puts "Created gemspec: #{file}"
|
40
|
+
end
|
data/lib/gemsconfig.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'gemsconfig/config'
|
3
|
+
|
4
|
+
module Gemsconfig
|
5
|
+
|
6
|
+
def self.init
|
7
|
+
@@config = Config.new
|
8
|
+
yield @@config
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.load
|
12
|
+
check_config(:load)
|
13
|
+
@@config.entries.each do |entry|
|
14
|
+
entry.load
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.install
|
19
|
+
check_config(:install)
|
20
|
+
@@config.entries.each do |entry|
|
21
|
+
entry.install unless entry.loaded?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def self.check_config(method)
|
28
|
+
raise "You need to initialize Gemsconfig with Gemsconfig::init before you #{method} your gemsconfig." unless @@config
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'entry'
|
3
|
+
|
4
|
+
module Gemsconfig
|
5
|
+
|
6
|
+
class Config
|
7
|
+
attr_reader :entries
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@entries = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def gem(name, opts={})
|
14
|
+
@entries << Entry.new(name, opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Gemsconfig
|
2
|
+
|
3
|
+
class Entry
|
4
|
+
|
5
|
+
attr_reader :name, :lib, :version, :source
|
6
|
+
|
7
|
+
def initialize(name, attrs)
|
8
|
+
attrs ||= {}
|
9
|
+
@name = name
|
10
|
+
@lib = attrs[:lib] || attrs['lib']
|
11
|
+
@version = attrs[:version] || attrs['version']
|
12
|
+
@source = attrs[:source] || attrs['source']
|
13
|
+
end
|
14
|
+
|
15
|
+
def load
|
16
|
+
begin
|
17
|
+
gem name, version_spec if @version
|
18
|
+
require (@lib || @name)
|
19
|
+
rescue LoadError => err
|
20
|
+
raise LoadError, "\nGemsconfig: could not load configured gem '#{@name}'#{" (#{@lib})" if @lib} - #{err.message}\n\nTry:\nrake gemsconfig:install\n--or--\n#{install_gem_command}\n\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def loaded?
|
25
|
+
%x(#{gem_command} #{list_command.join(' ')}).split("\n").detect{|listing| listing =~ Regexp.new("#{name}\s+.+#{Regexp.escape(@version) if @version}.+")}
|
26
|
+
end
|
27
|
+
|
28
|
+
def install
|
29
|
+
cmd = install_gem_command
|
30
|
+
puts cmd
|
31
|
+
puts %x(#{cmd})
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def install_gem_command
|
37
|
+
"#{gem_command} #{install_command.join(' ')}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def gem_command
|
41
|
+
case RUBY_PLATFORM
|
42
|
+
when /win32/
|
43
|
+
'gem.bat'
|
44
|
+
when /java/
|
45
|
+
'jruby -S gem'
|
46
|
+
else
|
47
|
+
'gem'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def list_command
|
52
|
+
%w(list --local)
|
53
|
+
end
|
54
|
+
|
55
|
+
def install_command
|
56
|
+
cmd = %w(install) << name
|
57
|
+
cmd << "--version" << version_spec if @version
|
58
|
+
cmd << "--source" << @source if @source
|
59
|
+
cmd
|
60
|
+
end
|
61
|
+
|
62
|
+
def version_spec
|
63
|
+
"=#{@version}"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# TODO: define cap task to allow you to deploy and run 'rake gemsconfig:install' before restart similar to deploy:migrations for Rails
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kelredd-gemsconfig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelly Redding
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: kelly@kelredd.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/gemsconfig
|
28
|
+
- lib/gemsconfig/config.rb
|
29
|
+
- lib/gemsconfig/entry.rb
|
30
|
+
- lib/gemsconfig/tasks
|
31
|
+
- lib/gemsconfig/tasks/cap.rb
|
32
|
+
- lib/gemsconfig/tasks/rake.rb
|
33
|
+
- lib/gemsconfig/version.rb
|
34
|
+
- lib/gemsconfig.rb
|
35
|
+
- test/test_helper.rb
|
36
|
+
- test/unit
|
37
|
+
- test/unit/gemsconfig_test.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: ""
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README.rdoc
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: A gem to manage gem configuration for a project, similar to Rails' config.gem (but in a very simple, dumb way)
|
65
|
+
test_files: []
|
66
|
+
|