require 0.1.8 → 0.2.0
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.markdown +10 -6
- data/lib/require.rb +105 -87
- data/lib/require/gemspec.rb +19 -13
- data/lib/require/tasks.rb +2 -2
- data/require.rb +2 -2
- data/spec/require/gemspec_spec.rb +3 -2
- metadata +2 -2
data/README.markdown
CHANGED
@@ -22,9 +22,10 @@ Create <code>require.rb</code> in your project's root directory:
|
|
22
22
|
|
23
23
|
<pre>
|
24
24
|
require 'rubygems'
|
25
|
+
gem 'require'
|
25
26
|
require 'require'
|
26
27
|
|
27
|
-
Require
|
28
|
+
Require do
|
28
29
|
|
29
30
|
gem(:sinatra, '=0.9.4') { require 'sinatra/base' }
|
30
31
|
gem(:haml, '=2.2.16') { require %w(haml sass) }
|
@@ -43,8 +44,11 @@ Then in your library file (<code>lib/whatever.rb</code>):
|
|
43
44
|
<pre>
|
44
45
|
require File.expand_path("#{File.dirname(__FILE_)}/../require")
|
45
46
|
Require.lib!
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
</pre>
|
48
|
+
|
49
|
+
What does <code>Require.lib!</code> do?
|
50
|
+
|
51
|
+
* Activates sinatra and haml gems
|
52
|
+
* Requires sinatra, haml, and sass
|
53
|
+
* Adds vendor/authlogic/lib to the load paths
|
54
|
+
* Requires authlogic
|
data/lib/require.rb
CHANGED
@@ -4,117 +4,135 @@ require "#{File.dirname(__FILE__)}/require/gemspec"
|
|
4
4
|
|
5
5
|
class Require
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
@@root = nil
|
7
|
+
@dsl = {}
|
8
|
+
@gemspec = {}
|
10
9
|
|
11
|
-
|
12
|
-
@@dsl.all *args
|
13
|
-
end
|
10
|
+
class <<self
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
def all(*args)
|
13
|
+
dsl.all *args
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
def call(&block)
|
17
|
+
dsl(true).call &block
|
18
|
+
end
|
19
|
+
|
20
|
+
def dsl(force=false)
|
21
|
+
@dsl[root(force)] ||= Dsl.new
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
def get(*args)
|
25
|
+
dsl.get *args
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def gemspec
|
29
|
+
(@gemspec[root] ||= Gemspec.new).instance
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
32
|
+
def name
|
33
|
+
(@gemspec[root] ||= Gemspec.new).name
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(method, value=nil, options=nil)
|
37
|
+
method = method.to_s
|
38
|
+
if method.include?('!')
|
39
|
+
method = method.gsub!('!', '').intern
|
40
|
+
gem = get(:gem, method)
|
41
|
+
profile = get(method)
|
42
|
+
if profile
|
43
|
+
profile.dsl.each do |dsl|
|
44
|
+
if dsl.gem?
|
45
|
+
require_gem! dsl.name, dsl.version, dsl.dsl
|
46
|
+
elsif dsl.load_path?
|
47
|
+
load_path! dsl.path
|
48
|
+
elsif dsl.require?
|
49
|
+
require! dsl.path
|
50
|
+
end
|
46
51
|
end
|
52
|
+
elsif gem
|
53
|
+
require_gem! gem.name
|
54
|
+
end
|
55
|
+
else
|
56
|
+
raise "Require##{method} does not exist"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def require!(paths)
|
61
|
+
return unless paths
|
62
|
+
[ paths ].flatten.each do |path|
|
63
|
+
path_with_root = "#{root}/#{path}"
|
64
|
+
if file_exists?(path_with_root)
|
65
|
+
Kernel.require path_with_root
|
66
|
+
else
|
67
|
+
Kernel.require path
|
47
68
|
end
|
48
|
-
elsif gem
|
49
|
-
require_gem! gem.name
|
50
69
|
end
|
51
|
-
else
|
52
|
-
raise "Require##{method} does not exist"
|
53
70
|
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.reset(root=nil, &block)
|
57
|
-
@@dsl = Dsl.new
|
58
|
-
@@gemspec = Gemspec.new
|
59
|
-
call root, &block
|
60
|
-
end
|
61
71
|
|
62
|
-
|
63
|
-
|
64
|
-
|
72
|
+
def reset(&block)
|
73
|
+
@dsl = {}
|
74
|
+
call &block
|
75
|
+
end
|
65
76
|
|
66
|
-
|
77
|
+
def root(force=false)
|
78
|
+
paths = caller.collect do |p|
|
79
|
+
File.expand_path(p.split(':').first)
|
80
|
+
end
|
81
|
+
path = paths.detect do |p|
|
82
|
+
!p.index(/\/require[-\.\d]*\/lib\//) &&
|
83
|
+
!p.include?('/rubygems/specification.rb') &&
|
84
|
+
!p.include?('/lib/rake/') &&
|
85
|
+
!p.include?('/lib/spec/')
|
86
|
+
end
|
87
|
+
paths = @dsl.keys.sort { |a,b| b.length <=> a.length }
|
88
|
+
if force
|
89
|
+
File.dirname(path)
|
90
|
+
else
|
91
|
+
paths.detect { |p| path[0..p.length-1] == p }
|
92
|
+
end
|
93
|
+
end
|
67
94
|
|
68
|
-
|
69
|
-
(File.exists?(path) && File.file?(path)) ||
|
70
|
-
(File.exists?("#{path}.rb") && File.file?("#{path}.rb"))
|
71
|
-
end
|
95
|
+
private
|
72
96
|
|
73
|
-
|
74
|
-
|
75
|
-
|
97
|
+
def dir_exists?(path)
|
98
|
+
File.exists?(path) && File.directory?(path)
|
99
|
+
end
|
76
100
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
path_with_root = "#{root}/#{path}"
|
81
|
-
if root && dir_exists?(path_with_root)
|
82
|
-
$: << path_with_root
|
83
|
-
else
|
84
|
-
$: << path
|
85
|
-
end
|
101
|
+
def file_exists?(path)
|
102
|
+
(File.exists?(path) && File.file?(path)) ||
|
103
|
+
(File.exists?("#{path}.rb") && File.file?("#{path}.rb"))
|
86
104
|
end
|
87
|
-
end
|
88
105
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if overwrite_dsl || gem.dsl
|
98
|
-
(overwrite_dsl || gem.dsl).all(:require).each do |dsl|
|
99
|
-
require! dsl.path
|
106
|
+
def load_path!(paths)
|
107
|
+
return unless paths
|
108
|
+
[ paths ].flatten.each do |path|
|
109
|
+
path_with_root = "#{root}/#{path}"
|
110
|
+
if root && dir_exists?(path_with_root)
|
111
|
+
$: << path_with_root
|
112
|
+
else
|
113
|
+
$: << path
|
100
114
|
end
|
101
115
|
end
|
102
116
|
end
|
103
|
-
end
|
104
117
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
118
|
+
def require_gem!(name, overwrite_version=nil, overwrite_dsl=nil)
|
119
|
+
gem = get(:gem, name)
|
120
|
+
if gem
|
121
|
+
if overwrite_version || gem.version
|
122
|
+
Kernel.send :gem, name.to_s, overwrite_version || gem.version
|
123
|
+
else
|
124
|
+
Kernel.send :gem, name.to_s
|
125
|
+
end
|
126
|
+
if overwrite_dsl || gem.dsl
|
127
|
+
(overwrite_dsl || gem.dsl).all(:require).each do |dsl|
|
128
|
+
require! dsl.path
|
129
|
+
end
|
130
|
+
end
|
113
131
|
end
|
114
132
|
end
|
115
133
|
end
|
116
134
|
end
|
117
135
|
|
118
|
-
def Require(
|
119
|
-
Require.call
|
136
|
+
def Require(&block)
|
137
|
+
Require.call &block
|
120
138
|
end
|
data/lib/require/gemspec.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
1
|
class Require
|
2
2
|
class Gemspec
|
3
|
-
|
3
|
+
|
4
4
|
def clean_paths(paths, more=nil)
|
5
5
|
paths.collect { |p| p.gsub("#{root}/#{more}", '') }
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def executables
|
9
9
|
clean_paths Dir["#{root}/bin/*"], 'bin/'
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def extra_doc_files
|
13
13
|
clean_paths Dir["#{root}/README.*"]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def files
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
gitignore = "#{root}/.gitignore"
|
18
|
+
ignore =
|
19
|
+
if File.exists?(gitignore)
|
20
|
+
File.read(gitignore).split("\n").collect do |path|
|
21
|
+
"#{root}/#{path.strip}"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
20
26
|
clean_paths (Dir["#{root}/**/*"] - Dir[*ignore])
|
21
27
|
end
|
22
|
-
|
28
|
+
|
23
29
|
def instance
|
24
30
|
raise "Require must be called with a root path parameter" unless root
|
25
|
-
|
31
|
+
|
26
32
|
defaults = {
|
27
33
|
:executables => executables,
|
28
34
|
:extra_rdoc_files => extra_doc_files,
|
@@ -31,7 +37,7 @@ class Require
|
|
31
37
|
:platform => Gem::Platform::RUBY,
|
32
38
|
:require_path => 'lib'
|
33
39
|
}
|
34
|
-
|
40
|
+
|
35
41
|
::Gem::Specification.new do |s|
|
36
42
|
Require.get(:gemspec).all.each do |(option, value)|
|
37
43
|
case option
|
@@ -53,13 +59,13 @@ class Require
|
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
56
|
-
|
62
|
+
|
57
63
|
def name
|
58
64
|
Require.get(:gemspec).get(:name)[1] rescue nil
|
59
65
|
end
|
60
|
-
|
66
|
+
|
61
67
|
def root
|
62
|
-
Require.root
|
68
|
+
@root ||= Require.root
|
63
69
|
end
|
64
70
|
end
|
65
71
|
end
|
data/lib/require/tasks.rb
CHANGED
data/require.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/lib/require"
|
2
2
|
|
3
|
-
Require
|
3
|
+
Require do
|
4
4
|
|
5
5
|
gem(:rake, '=0.8.7') { require 'rake' }
|
6
6
|
gem(:rspec, '=1.3.0')
|
@@ -11,7 +11,7 @@ Require File.dirname(__FILE__) do
|
|
11
11
|
name 'require'
|
12
12
|
homepage "http://github.com/winton/#{name}"
|
13
13
|
summary "Manage your project's dependencies with a pretty DSL"
|
14
|
-
version '0.
|
14
|
+
version '0.2.0'
|
15
15
|
end
|
16
16
|
|
17
17
|
rakefile do
|
@@ -4,7 +4,8 @@ class Require
|
|
4
4
|
describe Gemspec do
|
5
5
|
|
6
6
|
it "should generate a valid gemspec instance" do
|
7
|
-
Require.
|
7
|
+
Require.stub!(:root).and_return(SPEC + "/fixture")
|
8
|
+
Require.reset do
|
8
9
|
gem :rspec, '=1.3.0'
|
9
10
|
|
10
11
|
gemspec do
|
@@ -22,7 +23,7 @@ class Require
|
|
22
23
|
|
23
24
|
FileUtils.mkdir_p(File.expand_path("#{File.dirname(__FILE__)}/../fixture/ignore_me"))
|
24
25
|
|
25
|
-
s = Require.
|
26
|
+
s = Require.gemspec
|
26
27
|
s.authors.should == [ "Winton Welsh" ]
|
27
28
|
s.date.should == Time.utc(Date.today.year, Date.today.mon, Date.today.mday, 8)
|
28
29
|
s.default_executable.should == "bin"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: require
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Winton Welsh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-06 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|