24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/autoload_path.rb', line 24
def each_file source_path , *args, &block
options = args.
raise ArgumentError.new "Most supply a block" unless block_given?
source_path = Pathname.new(source_path)
prefix = options[:prefix]
except = (options[:except] || []).map{|i| i.to_s}
only = (options[:only] || []).map{|i| i.to_s}
original_source = options[:original_source] ? Pathname.new(options[:original_source]) : source_path
Dir.glob(source_path.join("*")).each do |path|
path = Pathname.new path
root = path
parent = path.parent.basename
actual = path.basename
if path.directory?
each_file path, original_source: original_source , prefix: prefix, except: except, only: only, &block
else
if actual == source_path
file_path = path.relative_path_from(original_source.parent)
root = original_source.parent
else
file_path = path.relative_path_from(original_source.parent.parent)
root = original_source.parent.parent
end
extname = file_path.extname
if prefix
file_path = prefix + file_path.to_s
else
file_path = File.join(root,file_path)
end
if only.length > 0
block.call(file_path, extname) if only.include?(file_path.to_s) && !except.include?(file_path.to_s)
else
block.call(file_path, extname) if (!except.include?(file_path.to_s) && !only.include?(file_path.to_s))
end
end
end
end
|