2015-08-13 03:47:02 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'vulcano/targets/dir'
|
|
|
|
require 'vulcano/targets/file'
|
|
|
|
|
|
|
|
module Vulcano::Targets
|
2015-08-13 05:34:24 +00:00
|
|
|
class FolderHelper
|
2015-08-13 03:47:02 +00:00
|
|
|
def handles?(target)
|
2015-09-04 07:15:20 +00:00
|
|
|
File.directory?(target)
|
2015-08-13 03:47:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def resolve(target)
|
|
|
|
# find all files in the folder
|
2015-09-05 14:07:54 +00:00
|
|
|
files = Dir[File.join(target, '**', '*')]
|
2015-08-13 03:47:02 +00:00
|
|
|
# remove the prefix
|
2015-09-05 14:07:54 +00:00
|
|
|
files = files.map { |x| x[target.length + 1..-1] }
|
2015-08-13 03:47:02 +00:00
|
|
|
# get the dirs helper
|
2015-09-09 10:18:42 +00:00
|
|
|
helper = DirsHelper.get_handler(files)
|
2015-08-13 03:47:02 +00:00
|
|
|
if helper.nil?
|
2015-09-03 21:24:42 +00:00
|
|
|
fail "Don't know how to handle folder #{target}"
|
2015-08-13 03:47:02 +00:00
|
|
|
end
|
|
|
|
# get all file contents
|
|
|
|
file_handler = Vulcano::Targets.modules['file']
|
|
|
|
test_files = helper.get_filenames(files)
|
|
|
|
test_files.map do |f|
|
2015-09-05 14:07:54 +00:00
|
|
|
file_handler.resolve(File.join(target, f))
|
2015-08-13 03:47:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-13 05:34:24 +00:00
|
|
|
Vulcano::Targets.add_module('folder', FolderHelper.new)
|
2015-08-13 03:47:02 +00:00
|
|
|
end
|