Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changing project name to require

  • Loading branch information...
commit 565e80c79f955a6d3eae352c19dc539fd7cee151 1 parent 0220e6e
@winton authored
View
46 README.markdown
@@ -1,11 +1,49 @@
-Dep
-===
+Require
+=======
-Dependency manager.
+Manage multiple dependency profiles from a single file.
+
+* Gem activation
+* Require calls
+* Load paths
+* Gemspec configuration
Install
-------
<pre>
-sudo gem install dep
+sudo gem install require
+</pre>
+
+Example
+-------
+
+Create <code>require.rb</code> in your project's root directory:
+
+<pre>
+require 'rubygems'
+require 'require'
+
+Require File.dirname(__FILE__) do
+
+ gem(:sinatra, '=0.9.4') { require 'sinatra/base' }
+ gem(:haml, '=2.2.16') { require %w(haml sass) }
+
+ lib do
+ gem :sinatra
+ gem :haml
+ load_path 'vendor/authlogic/lib'
+ require 'authlogic'
+ end
+end
+</pre>
+
+Then in your library file (<code>lib/whatever.rb</code>):
+
+<pre>
+require File.expand_path("#{File.dirname(__FILE_)}/../require")
+Require.lib!
+ # Activates sinatra and haml gems
+ # Adds vendor/authlogic/lib to the load paths
+ # Requires authlogic
</pre>
View
4 Rakefile
@@ -1,2 +1,2 @@
-require "#{File.dirname(__FILE__)}/config/dep"
-Dep.rakefile!
+require "#{File.dirname(__FILE__)}/require"
+Require.rakefile!
View
18 lib/dep/tasks.rb
@@ -1,18 +0,0 @@
-desc "Package gem"
-Rake::GemPackageTask.new(Dep.instance) do |pkg|
- pkg.gem_spec = Dep.instance
-end
-
-desc "Install gem"
-task :install do
- Rake::Task['gem'].invoke
- `sudo gem uninstall #{Dep.name} -x`
- `sudo gem install pkg/#{Dep.name}*.gem`
- `rm -Rf pkg`
-end
-
-desc "Run specs"
-Spec::Rake::SpecTask.new do |t|
- t.spec_opts = ["--format", "specdoc", "--colour"]
- t.spec_files = Dir["#{Dep.root}/spec/**/*_spec.rb"]
-end
View
24 lib/dep.rb → lib/require.rb
@@ -1,13 +1,15 @@
require 'rubygems'
-require "#{File.dirname(__FILE__)}/dep/dsl"
-require "#{File.dirname(__FILE__)}/dep/gemspec"
+require "#{File.dirname(__FILE__)}/require/dsl"
+require "#{File.dirname(__FILE__)}/require/gemspec"
-class Dep
+class Require
@@dsl = Dsl.new
@@gemspec = Gemspec.new
+ @@root = nil
- def self.call(&block)
+ def self.call(root=nil, &block)
+ @@root = File.expand_path(root) if root
@@dsl.call &block
end
@@ -43,18 +45,18 @@ def self.method_missing(method, value=nil, options=nil)
require_gem! gem.name
end
else
- raise "Dep##{method} does not exist"
+ raise "Require##{method} does not exist"
end
end
- def self.reset(&block)
+ def self.reset(root=nil, &block)
@@dsl = Dsl.new
@@gemspec = Gemspec.new
- call &block
+ call root, &block
end
def self.root
- @@gemspec.root
+ @@root
end
private
@@ -103,6 +105,6 @@ def self.require!(paths)
end
end
-def Dep(&block)
- Dep.call &block
-end
+def Require(root=nil, &block)
+ Require.call root, &block
+end
View
6 lib/dep/dsl.rb → lib/require/dsl.rb
@@ -1,4 +1,4 @@
-class Dep
+class Require
class Dsl < Array
def all(*values)
@@ -46,7 +46,7 @@ def all(*values)
end
def dsl
- self[-1] if self[-1].class == Dep::Dsl::Args || self[-1].class == Dsl
+ self[-1] if self[-1].class == Require::Dsl::Args || self[-1].class == Dsl
end
def get(*values)
@@ -78,4 +78,4 @@ def version
end
end
end
-end
+end
View
13 lib/dep/gemspec.rb → lib/require/gemspec.rb
@@ -1,4 +1,4 @@
-class Dep
+class Require
class Gemspec
def clean_paths(paths, more=nil)
@@ -21,6 +21,7 @@ def files
end
def instance
+ raise "Require must be called with a root path parameter" unless root
defaults = {
:executables => executables,
@@ -32,11 +33,11 @@ def instance
}
::Gem::Specification.new do |s|
- Dep.get(:gemspec).all.each do |(option, value)|
+ Require.get(:gemspec).all.each do |(option, value)|
case option
when :dependencies then
value.all(:gem).each do |dependency|
- gem = Dep.get(:gem, dependency.name)
+ gem = Require.get(:gem, dependency.name)
version = dependency.version || (gem.version rescue nil)
s.add_dependency(dependency.name.to_s, version)
end
@@ -54,11 +55,11 @@ def instance
end
def name
- Dep.get(:gemspec).get(:name)[1] rescue nil
+ Require.get(:gemspec).get(:name)[1] rescue nil
end
def root
- Dep.get(:gemspec).get(:root)[1] rescue nil
+ Require.root
end
end
-end
+end
View
2  lib/dep/spec_helper.rb → lib/require/spec_helper.rb
@@ -1,6 +1,6 @@
$testing = true
SPEC = File.dirname(__FILE__)
-$:.unshift File.expand_path("#{Dep.root}/lib")
+$:.unshift File.expand_path("#{Require.root}/lib")
# For use with rspec textmate bundle
def debug(object)
View
18 lib/require/tasks.rb
@@ -0,0 +1,18 @@
+desc "Package gem"
+Rake::GemPackageTask.new(Require.instance) do |pkg|
+ pkg.gem_spec = Require.instance
+end
+
+desc "Install gem"
+task :install do
+ Rake::Task['gem'].invoke
+ `sudo gem uninstall #{Require.name} -x`
+ `sudo gem install pkg/#{Require.name}*.gem`
+ `rm -Rf pkg`
+end
+
+desc "Run specs"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_opts = ["--format", "specdoc", "--colour"]
+ t.spec_files = Dir["#{Require.root}/spec/**/*_spec.rb"]
+end
View
13 config/dep.rb → require.rb
@@ -1,23 +1,22 @@
-require File.expand_path("#{File.dirname(__FILE__)}/../lib/dep")
+require "#{File.dirname(__FILE__)}/lib/require"
-Dep do
+Require File.dirname(__FILE__) do
gem(:rake, '=0.8.7') { require 'rake' }
- gem(:rspec, '=1.3.0') { require 'rspec' }
+ gem(:rspec, '=1.3.0')
gemspec do
author 'Winton Welsh'
email 'mail@wintoni.us'
- name 'dep'
+ name 'require'
homepage "http://github.com/winton/#{name}"
- root File.expand_path("#{File.dirname(__FILE__)}/../")
summary "Dependency manager"
- version '0.1.3'
+ version '0.1.4'
end
rakefile do
gem(:rake) { require 'rake/gempackagetask' }
gem(:rspec) { require 'spec/rake/spectask' }
- require 'lib/dep/tasks'
+ require 'lib/require/tasks'
end
end
View
14 spec/dep/dsl_spec.rb → spec/require/dsl_spec.rb
@@ -1,16 +1,16 @@
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
-class Dep
+class Require
describe Dsl do
it "should store method calls and a value, options array" do
- dsl = Dep::Dsl.new
+ dsl = Require::Dsl.new
dsl.call { a 1, 2, 3 }
dsl.should == [[:a, 1, 2, 3]]
end
it "should store child blocks" do
- dsl = Dep::Dsl.new
+ dsl = Require::Dsl.new
dsl.call do
a 1 do
b 2
@@ -20,7 +20,7 @@ class Dep
end
it "should be able to retrieve a value from the block" do
- dsl = Dep::Dsl.new
+ dsl = Require::Dsl.new
dsl.call do
a 1
b a
@@ -29,7 +29,7 @@ class Dep
end
it "should provide a get method" do
- dsl = Dep::Dsl.new
+ dsl = Require::Dsl.new
dsl.call do
a 1 do
b 2
@@ -43,7 +43,7 @@ class Dep
end
it "should provide an all method" do
- dsl = Dep::Dsl.new
+ dsl = Require::Dsl.new
dsl.call do
a 1
a 2 do
@@ -57,4 +57,4 @@ class Dep
dsl.all(:a).last.all(:b).should == [[:b, 3], [:b, 4]]
end
end
-end
+end
View
15 spec/dep/gemspec_spec.rb → spec/require/gemspec_spec.rb
@@ -1,10 +1,10 @@
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
-class Dep
+class Require
describe Gemspec do
it "should generate a valid gemspec instance" do
- Dep.reset do
+ Require.reset "#{File.dirname(__FILE__)}/../fixture" do
gem :rspec, '=1.3.0'
gemspec do
@@ -13,9 +13,8 @@ class Dep
gem :rspec
end
email 'mail@wintoni.us'
- name 'gem_template'
+ name 'require'
homepage "http://github.com/winton/#{name}"
- root File.expand_path("#{File.dirname(__FILE__)}/../fixture")
summary "summary"
version '0.1.0'
end
@@ -23,7 +22,7 @@ class Dep
FileUtils.mkdir_p(File.expand_path("#{File.dirname(__FILE__)}/../fixture/ignore_me"))
- s = Dep.instance
+ s = Require.instance
s.authors.should == [ "Winton Welsh" ]
s.date.should == Time.utc(Date.today.year, Date.today.mon, Date.today.mday, 8)
s.default_executable.should == "bin"
@@ -32,10 +31,10 @@ class Dep
s.executables.should == ["bin"]
s.extra_rdoc_files.should == ["README.markdown"]
s.files.should == ["bin", "bin/bin", "lib", "lib/lib.rb", "README.markdown"]
- s.homepage.should == "http://github.com/winton/gem_template"
- s.name.should == "gem_template"
+ s.homepage.should == "http://github.com/winton/require"
+ s.name.should == "require"
s.require_paths.should == ["lib"]
s.summary.should == 'summary'
end
end
-end
+end
View
34 spec/dep_spec.rb → spec/require_spec.rb
@@ -1,10 +1,10 @@
require "#{File.dirname(__FILE__)}/spec_helper"
-describe Dep do
+describe Require do
before(:all) do
@fixture = File.dirname(__FILE__) + '/fixture'
- Dep.reset do
+ Require.reset do
gem :rake, '=0.8.7'
gem(:rspec, '=1.3.0') { require 'spec' }
@@ -18,38 +18,38 @@
end
it "should provide a load_path! method" do
- Dep.send :load_path!, @fixture
+ Require.send :load_path!, @fixture
$:.include?(@fixture).should == true
end
it "should provide a require_gem! method" do
Kernel.should_receive(:gem).with('rspec', '=1.3.0')
- Dep.should_receive(:require!).with('spec')
- Dep.send :require_gem!, :rspec
+ Require.should_receive(:require!).with('spec')
+ Require.send :require_gem!, :rspec
end
it "should provide a require_gem! method with optional overwrite methods" do
Kernel.should_receive(:gem).with('rspec', '>1.2.9')
- Dep.should_receive(:require!).with('spec/rake/spectask')
- dsl = Dep.get(:rakefile).get(:gem, :rspec).last
- Dep.send :require_gem!, :rspec, '>1.2.9', dsl
+ Require.should_receive(:require!).with('spec/rake/spectask')
+ dsl = Require.get(:rakefile).get(:gem, :rspec).last
+ Require.send :require_gem!, :rspec, '>1.2.9', dsl
end
it "should provide a require! method" do
Kernel.should_receive(:require).with('spec')
- Dep.send :require!, 'spec'
+ Require.send :require!, 'spec'
end
it "should require gems through the bang shortcut" do
- Dep.should_receive(:require_gem!).with(:rspec)
- Dep.rspec!
+ Require.should_receive(:require_gem!).with(:rspec)
+ Require.rspec!
end
it "should require profiles through the bang shortcut" do
- Dep.should_receive(:require!).with('test')
- Dep.should_receive(:require_gem!).with(:rake, nil, [[:require, "rake/gempackagetask"]])
- Dep.should_receive(:require_gem!).with(:rspec, '>1.2.9', [[:require, "spec/rake/spectask"]])
- Dep.should_receive(:load_path!).with(@fixture)
- Dep.rakefile!
+ Require.should_receive(:require!).with('test')
+ Require.should_receive(:require_gem!).with(:rake, nil, [[:require, "rake/gempackagetask"]])
+ Require.should_receive(:require_gem!).with(:rspec, '>1.2.9', [[:require, "spec/rake/spectask"]])
+ Require.should_receive(:load_path!).with(@fixture)
+ Require.rakefile!
end
-end
+end
View
4 spec/spec_helper.rb
@@ -2,7 +2,7 @@
SPEC = File.dirname(__FILE__)
$:.unshift File.expand_path("#{SPEC}/../lib")
-require 'dep'
+require 'require'
require 'pp'
# For use with rspec textmate bundle
@@ -13,4 +13,4 @@ def debug(object)
end
Spec::Runner.configure do |config|
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.