Module: Requirer
- Defined in:
- lib/requirer.rb,
lib/requirer/version.rb
Defined Under Namespace
Classes: DirUtilsException
Constant Summary
collapse
- VERSION =
"0.0.5"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.logger ⇒ Object
12
13
14
15
16
|
# File 'lib/requirer.rb', line 12
def logger
@logger ||= Logger.new($stdout).tap do |log|
log.progname = self.name
end
end
|
Class Method Details
.find_dir_with(path, search_dirs = $LOAD_PATH) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/requirer.rb', line 46
def find_dir_with(path, search_dirs=$LOAD_PATH)
fail DirUtilsException.new("No such path: #{path}") unless path
path = path.to_s
return path if path[0]=='/'
search_dirs.each do |dir|
dirname = File.expand_path(path, dir)
return dirname if File.directory?(dirname)
end
fail DirUtilsException.new("No such path: #{path}")
end
|
.find_file_with(path, search_dirs = $LOAD_PATH) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/requirer.rb', line 57
def find_file_with(path, search_dirs=$LOAD_PATH)
fail DirUtilsException.new("No such path: #{path}") unless path
if path[0]=='/'
fail DirUtilsException.new("No such path: #{path}") unless File.exists?(path)
return path
end
search_dirs.each do |dir|
filename = File.expand_path(path, dir)
return filename if File.file?(filename)
end
fail DirUtilsException.new("No such path: #{path}")
end
|
.on_dir_tree(path, &block) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/requirer.rb', line 74
def on_dir_tree(path, &block)
return nil unless path
block.call path
dirs = Dir["#{path}/*"].select{ |f| File.directory?(f) }
dirs.each{ |dir| on_dir_tree dir, &block }
end
|
.require_absolute_dir(path) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/requirer.rb', line 35
def require_absolute_dir(path)
return nil unless path
Requirer.logger.debug "requiring absolute dir:#{path}:"
Dir["#{path}/[^_]*.rb"].sort.each do |file|
next unless File.file?(file)
Requirer.logger.debug "requiring file:#{file}:"
require_dependency file
end
end
|
.require_dir(path) ⇒ Object
29
30
31
32
|
# File 'lib/requirer.rb', line 29
def require_dir(path)
Requirer.logger.debug "require_dir:#{path}:"
require_absolute_dir find_dir_with(path, $LOAD_PATH)
end
|
.require_dir_tree(path) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/requirer.rb', line 21
def require_dir_tree(path)
Requirer.logger.debug "dir_tree #{path}"
path = find_dir_with(path, $LOAD_PATH)
on_dir_tree(path) do |dir_path|
require_absolute_dir dir_path
end
end
|
.where_is?(path) ⇒ Boolean
70
71
72
|
# File 'lib/requirer.rb', line 70
def where_is?(path)
find_file_with path
end
|