vitamined-gems 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +72 -0
- data/lib/vitamined-gems.rb +91 -0
- metadata +57 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
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/README.rdoc
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= Vitamined gems
|
2
|
+
|
3
|
+
Powered config.gem syntax to make your enviroment DRY
|
4
|
+
|
5
|
+
Until the {gem bundler}[http://github.com/wycats/bundler] dominates the entire
|
6
|
+
world you can ease the pain of defining gem dependencies by vitamining your
|
7
|
+
environment file, avoiding, for example, the burden of adding :lib and :source
|
8
|
+
parameters when requiring github gems.
|
9
|
+
|
10
|
+
config.gem.github 'yfactorial-utility_scopes'
|
11
|
+
|
12
|
+
Many thanks to {Bruce Williams}[http://codefluency.com] for the {original idea}[http://codefluency.com/2009/02/07/a-githubby-config-gem-hack.html]
|
13
|
+
that inspirated this code. Thanks as well to {Marcos Arias}[(http://github.com/yizzreel)] for
|
14
|
+
his comments.
|
15
|
+
|
16
|
+
This gem has been tested with Rails 2.2.x and Rails 2.3.x versions
|
17
|
+
|
18
|
+
== Installation
|
19
|
+
|
20
|
+
Just install the gem from {Gemcutter}[http://gemcutter.org]
|
21
|
+
|
22
|
+
$ gem install vitamined-gems --source http://gemcutter.org
|
23
|
+
|
24
|
+
== Usage
|
25
|
+
|
26
|
+
In your environment.rb file, load and initialize the gem before the
|
27
|
+
Rails::Initializer.run line.
|
28
|
+
|
29
|
+
require 'vitamined-gems'
|
30
|
+
vitamine_gems!
|
31
|
+
|
32
|
+
After that you can use the extended syntax. By default github and gemcutter gems
|
33
|
+
are supported. Github gems automatically set the :lib and :source parameters,
|
34
|
+
while Gemcutter gems set the :source. You can override those values by providing
|
35
|
+
your own. The following config:
|
36
|
+
|
37
|
+
config.gem.cutter 'sugarfree-config', :version => '1.0.0'
|
38
|
+
config.gem.github 'yfactorial-utility_scopes', :version => '2.0.1'
|
39
|
+
|
40
|
+
is equivalent to:
|
41
|
+
|
42
|
+
config.gem.gemcutter 'sugarfree-config', :version => '1.0.0', :source => 'http://gemcutter.org'
|
43
|
+
config.gem.github 'yfactorial-utility_scopes', :version => '2.0.1', :lib => 'utility_scopes', :source => 'http://gems.github.org'
|
44
|
+
|
45
|
+
== Further customization
|
46
|
+
|
47
|
+
You can add more vitamins or override the exsisting ones by passing a block to
|
48
|
+
the vitamine_gems! method like this
|
49
|
+
|
50
|
+
vitamine_gems! do
|
51
|
+
github do |name, options|
|
52
|
+
{ :lib => name.split('-', 2).last, :source => 'http://gems.github.org' }
|
53
|
+
end
|
54
|
+
|
55
|
+
cutter :source => 'http://gemcutter.org'
|
56
|
+
end
|
57
|
+
|
58
|
+
or you can put a vitamin.rb file in the RAILS_ROOT/config folder
|
59
|
+
|
60
|
+
github do |name, options|
|
61
|
+
{ :lib => name.split('-', 2).last, :source => 'http://gems.github.org' }
|
62
|
+
end
|
63
|
+
|
64
|
+
cutter :source => 'http://gemcutter.org'
|
65
|
+
|
66
|
+
You can use both methods of customization in parallel. Just remember that in case
|
67
|
+
of name clashing the block based config overrides the file based config.
|
68
|
+
|
69
|
+
== Contact
|
70
|
+
|
71
|
+
Please mail bugs, suggestions and patches to
|
72
|
+
contact@davidbarral.com[mailto:contact@davidbarral.com]
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module VitaminedGems
|
2
|
+
|
3
|
+
VITAMINS_FILE = File.join(::Rails.root, 'config', 'vitamins.rb')
|
4
|
+
|
5
|
+
def self.initialize(&block)
|
6
|
+
@@vitamins = {
|
7
|
+
:github => lambda { |name, _| { :lib => name.split('-', 2).last, :source => 'http://gems.github.com' } },
|
8
|
+
:cutter => { :source => 'http://gemcutter.org' }
|
9
|
+
}
|
10
|
+
|
11
|
+
if File.exists?(VITAMINS_FILE)
|
12
|
+
@@vitamins.merge!(VitaminExtractor.new(File.read(VITAMINS_FILE)).extract)
|
13
|
+
end
|
14
|
+
|
15
|
+
if block_given?
|
16
|
+
@@vitamins.merge!(VitaminExtractor.new(&block).extract)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def gem_with_vitamins(*args)
|
21
|
+
args.empty? ? VitaminedGem.new(self, @@vitamins) : gem_without_vitamins(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
class UnknownVitamin < Exception
|
25
|
+
def initialize(vitamin_name)
|
26
|
+
super("Cannot find '#{vitamin_name}' vitamin")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class VitaminedGem
|
31
|
+
|
32
|
+
def initialize(rails_configuration, vitamins)
|
33
|
+
@rails_configuration = rails_configuration
|
34
|
+
@vitamins = vitamins
|
35
|
+
end
|
36
|
+
|
37
|
+
def respond_to?(method)
|
38
|
+
@vitamins.has_key?(method.to_sym) || super.respond_to?(method)
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(vitamin_name, gem_name, options = {})
|
42
|
+
if vitamin = @vitamins[vitamin_name]
|
43
|
+
options = if vitamin.is_a? Hash
|
44
|
+
vitamin.merge(options)
|
45
|
+
else
|
46
|
+
vitamin.call(gem_name, options).merge(options)
|
47
|
+
end
|
48
|
+
@rails_configuration.gem(gem_name, options)
|
49
|
+
else
|
50
|
+
raise UnknownVitamin.new(vitamin_name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class VitaminExtractor
|
56
|
+
|
57
|
+
def initialize(from = nil, &block)
|
58
|
+
@from = from || block
|
59
|
+
@extracted_vitamins = {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def extract
|
63
|
+
if @from.is_a? Proc
|
64
|
+
instance_eval(&@from)
|
65
|
+
else
|
66
|
+
instance_eval(@from)
|
67
|
+
end
|
68
|
+
@extracted_vitamins
|
69
|
+
end
|
70
|
+
|
71
|
+
def method_missing(symbol, *args, &block)
|
72
|
+
@extracted_vitamins[symbol] = block_given? ? block : args.first
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
#
|
79
|
+
# Setup method for the vitamined gems!! This pill should only be prescribed to
|
80
|
+
# a Rails application ;)
|
81
|
+
#
|
82
|
+
def vitamine_gems!(&block)
|
83
|
+
|
84
|
+
Rails::Configuration.class_eval do
|
85
|
+
include VitaminedGems
|
86
|
+
alias :gem_without_vitamins :gem
|
87
|
+
alias :gem :gem_with_vitamins
|
88
|
+
end
|
89
|
+
|
90
|
+
VitaminedGems.initialize(&block)
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vitamined-gems
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Barral
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-16 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Powered config.gem syntax to make your enviroment DRY
|
17
|
+
email: contact@davidbarral.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- LICENSE
|
27
|
+
- lib/vitamined-gems.rb
|
28
|
+
has_rdoc: true
|
29
|
+
homepage: http://github.com/davidbarral/vitamined-gems
|
30
|
+
licenses: []
|
31
|
+
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "1.2"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.3.5
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Powered config.gem syntax
|
56
|
+
test_files: []
|
57
|
+
|