require 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +40 -3
  2. data/lib/require.rb +19 -19
  3. data/require.rb +1 -1
  4. metadata +1 -1
data/README.markdown CHANGED
@@ -46,9 +46,46 @@ require File.expand_path("#{File.dirname(__FILE_)}/../require")
46
46
  Require.lib!
47
47
  </pre>
48
48
 
49
- What does <code>Require.lib!</code> do?
50
-
51
49
  * Activates sinatra and haml gems
52
50
  * Requires sinatra, haml, and sass
53
51
  * Adds vendor/authlogic/lib to the load paths
54
- * Requires authlogic
52
+ * Requires authlogic
53
+
54
+ Gemspec
55
+ -------
56
+
57
+ You can also use <code>Require</code> to generate a <code>Gem::Specification</code> instance.
58
+
59
+ <pre>
60
+ require 'rubygems'
61
+ gem 'require'
62
+ require 'require'
63
+
64
+ Require do
65
+
66
+ gem(:sinatra, '=0.9.4') { require 'sinatra/base' }
67
+
68
+ gemspec do
69
+ author 'Your Name'
70
+ dependencies do
71
+ gem :sinatra
72
+ end
73
+ email 'your@email.com'
74
+ name 'my_project'
75
+ homepage "http://github.com/your_name/#{name}"
76
+ summary ""
77
+ version '0.1.0'
78
+ end
79
+ end
80
+ </pre>
81
+
82
+ Then use it in your <code>rakefile</code>:
83
+
84
+ <pre>
85
+ require File.dirname(__FILE_) + "/require"
86
+
87
+ desc "Package gem"
88
+ Rake::GemPackageTask.new(Require.gemspec) do |pkg|
89
+ pkg.gem_spec = Require.gemspec
90
+ end
91
+ </pre>
data/lib/require.rb CHANGED
@@ -13,12 +13,12 @@ class Require
13
13
  dsl.all *args
14
14
  end
15
15
 
16
- def call(&block)
17
- dsl(true).call &block
16
+ def call(force_root=nil, &block)
17
+ dsl(force_root).call &block
18
18
  end
19
19
 
20
- def dsl(force=false)
21
- @dsl[root(force)] ||= Dsl.new
20
+ def dsl(force_root=nil)
21
+ @dsl[root(force_root)] ||= Dsl.new
22
22
  end
23
23
 
24
24
  def get(*args)
@@ -71,28 +71,28 @@ class Require
71
71
 
72
72
  def reset(&block)
73
73
  @dsl = {}
74
- call &block
74
+ call caller[0], &block
75
75
  end
76
76
 
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 }
77
+ def root(force=nil)
88
78
  if force
89
- File.dirname(path)
79
+ return clean_caller(force)
90
80
  else
91
- paths.detect { |p| path[0..p.length-1] == p }
81
+ roots = @dsl.keys.sort { |a,b| b.length <=> a.length }
82
+ root = roots.detect do |r|
83
+ caller.detect do |c|
84
+ clean_caller(c)[0..r.length-1] == r
85
+ end
86
+ end
87
+ root ? root : raise("You have not executed a Require block (Require not configured)")
92
88
  end
93
89
  end
94
90
 
95
91
  private
92
+
93
+ def clean_caller(string)
94
+ File.dirname(File.expand_path(string.split(':').first))
95
+ end
96
96
 
97
97
  def dir_exists?(path)
98
98
  File.exists?(path) && File.directory?(path)
@@ -134,5 +134,5 @@ class Require
134
134
  end
135
135
 
136
136
  def Require(&block)
137
- Require.call &block
137
+ Require.call caller[0], &block
138
138
  end
data/require.rb CHANGED
@@ -11,7 +11,7 @@ Require 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.2.0'
14
+ version '0.2.1'
15
15
  end
16
16
 
17
17
  rakefile do
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh