class DirDSL
Constants
- VERSION
Attributes
from_root[R]
to_root[R]
Public Class Methods
new(from_root, to_root)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 9 def initialize from_root, to_root @from_root = File.expand_path(from_root) @to_root = File.expand_path(to_root) @global_ignores = [] end
Public Instance Methods
build(&block)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 15 def build(&block) MetaMethods::DslBuilder.instance.evaluate_dsl(self, nil, block) end
content(params)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 54 def content params source = params[:source] stream = source.kind_of?(String) ? StringIO.new(source) : source content = stream.read to_dir = to_dir(params[:to_dir], params[:name]) create_directory to_dir unless File.exist? to_dir write_content_to_file content, "#{to_dir}/#{File.basename(params[:name])}" end
directory(params)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 67 def directory params if params[:from_dir] if params[:to_dir] == "." || params[:to_dir].nil? to_dir = params[:from_dir] else to_dir = params[:to_dir] end filter = params[:filter].nil? ? "**/*" : params[:filter] excludes = parse_excludes(params[:excludes]) copy_files_with_excludes "#{from_root}/#{params[:from_dir]}", "#{to_root}/#{to_dir}", filter, excludes else to_dir = "#{to_root}/#{params[:to_dir]}" create_directory to_dir unless File.exist? to_dir end end
entries_size()
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 27 def entries_size list = Dir.glob("#{to_root}/**/*") cnt = 0 list.each do |name| cnt += 1 if File.file?(name) end cnt end
entry_exist?(entry_name)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 23 def entry_exist? entry_name File.exist? "#{to_root}/#{entry_name}" end
file(params)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 46 def file params to_dir = to_dir(params[:to_dir], params[:name]) create_directory to_dir unless File.exist? to_dir write_to_file "#{from_root}/#{params[:name]}", "#{to_dir}/#{File.basename(params[:name])}" end
global_ignore(ignore)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 19 def global_ignore ignore @global_ignores << ignore end
list(dir=".")
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 38 def list dir="." list = pattern_to_files "#{from_root}/#{dir}", "**/*" list.each_with_index do |name, index| list[index] = name["#{from_root}/#{dir}".length+1..-1] end end
Private Instance Methods
copy_files_with_excludes(from_dir, to_dir, pattern, excludes)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 106 def copy_files_with_excludes from_dir, to_dir, pattern, excludes create_directory to_dir files = pattern_to_files from_dir, pattern files.each do |file| if File.file? file and not file_excluded(file, excludes) FileUtils.cp(file, to_dir) elsif File.directory?(file) and not dir_in_global_ignores(file, @global_ignores) FileUtils.mkdir_p file end end end
dir_in_global_ignores(dir, global_ignores)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 120 def dir_in_global_ignores dir, global_ignores ignored = false global_ignores.each do |exclude| if dir =~ /#{exclude}/ ignored = true break end end ignored end
file_excluded(file, excludes)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 133 def file_excluded(file, excludes) excluded = false excludes.each do |exclude| if file =~ /#{exclude}/ excluded = true break end end excluded end
parse_excludes(excludes)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 98 def parse_excludes excludes if excludes excludes.split(",").map(&:strip) else [] end end
to_dir(dir, name)
click to toggle source
# File lib/dir_dsl/dir_dsl.rb, line 88 def to_dir dir, name dir = File.dirname(name) unless dir if dir == "." to_root else "#{to_root}/#{dir}" end end