Class: Require
- Inherits:
-
Object
show all
- Defined in:
- lib/require.rb,
lib/require/dsl.rb,
lib/require/tasks.rb,
lib/require/gemspec.rb
Defined Under Namespace
Modules: Tasks
Classes: Dsl, Gemspec
Class Method Summary
collapse
Class Method Details
.all(*args) ⇒ Object
12
13
14
|
# File 'lib/require.rb', line 12
def all(*args)
dsl.all *args
end
|
.call(force_root = nil, &block) ⇒ Object
16
17
18
|
# File 'lib/require.rb', line 16
def call(force_root=nil, &block)
dsl(force_root).call &block
end
|
.dsl(force_root = nil) ⇒ Object
20
21
22
|
# File 'lib/require.rb', line 20
def dsl(force_root=nil)
@dsl[root(force_root)] ||= Dsl.new
end
|
.gemspec ⇒ Object
28
29
30
|
# File 'lib/require.rb', line 28
def gemspec
(@gemspec[root] ||= Gemspec.new).instance
end
|
.get(*args) ⇒ Object
24
25
26
|
# File 'lib/require.rb', line 24
def get(*args)
dsl.get *args
end
|
.method_missing(method, value = nil, options = nil) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/require.rb', line 36
def method_missing(method, value=nil, options=nil)
method = method.to_s
if method.include?('!')
method = method.gsub!('!', '').intern
gem = get(:gem, method)
profile = get(method)
if profile
profile.dsl.each do |dsl|
if dsl.gem?
require_gem! dsl.name, dsl.version, dsl.dsl
elsif dsl.load_path?
load_path! dsl.path
elsif dsl.require?
require! dsl.path
end
end
elsif gem
require_gem! gem.name
end
else
raise "Require##{method} does not exist"
end
end
|
.name ⇒ Object
32
33
34
|
# File 'lib/require.rb', line 32
def name
(@gemspec[root] ||= Gemspec.new).name
end
|
.require!(paths) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/require.rb', line 60
def require!(paths)
return unless paths
[ paths ].flatten.each do |path|
path_with_root = "#{root}/#{path}"
if file_exists?(path_with_root)
Kernel.require path_with_root
else
Kernel.require path
end
end
end
|
.reset(&block) ⇒ Object
72
73
74
75
|
# File 'lib/require.rb', line 72
def reset(&block)
@dsl = {}
call caller[0], &block
end
|
.root(force = nil) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/require.rb', line 77
def root(force=nil)
if force
return clean_caller(force)
else
roots = @dsl.keys.sort { |a,b| b.length <=> a.length }
root = roots.detect do |r|
caller.detect do |c|
clean_caller(c)[0..r.length-1] == r
end
end
if root
root
elsif defined?(::Rake)
Rake.original_dir
else
raise("You have not executed a Require block (Require not configured)")
end
end
end
|