module Mygen::Files
Public Instance Methods
directory_exists?(path)
click to toggle source
# File lib/mygen/files.rb, line 43 def directory_exists?(path) File.directory?(path) && File.exist?(path) end
file_destination(file, bindings)
click to toggle source
# File lib/mygen/files.rb, line 19 def file_destination(file, bindings) # subtract template_source_dir from path, add dest_dir and substitute filenames new_file = file.gsub(template_source_dir, '') replaced_filename(new_file, bindings) end
internal_template_files()
click to toggle source
# File lib/mygen/files.rb, line 11 def internal_template_files template_files(internal_template_source_dir) end
internal_template_source_dir()
click to toggle source
# File lib/mygen/files.rb, line 15 def internal_template_source_dir File.join(Mygen.root, "templates", generator_name) end
move_file_in_place(src, dest)
click to toggle source
# File lib/mygen/files.rb, line 25 def move_file_in_place(src, dest) sf = File.absolute_path(src) df = File.absolute_path(dest) file_exist = File.exist?(df) fileutils.mv(sf, df) if sf != df && !file_exist if file_exist && sf != df Dir.glob(File.join(sf, "/*")).each do |f| next if f == sf file = f.sub(sf, '') new_name = File.join(df, file) next if directory_exists? new_name fileutils.mv(f, File.join(df, file)) end fileutils.rm_rf(sf) end end
template_dirs(path = template_source_dir)
click to toggle source
# File lib/mygen/files.rb, line 7 def template_dirs(path = template_source_dir) Dir.glob(File.join(path, "**/*")).select { |f| File.directory? f } end
template_files(path = template_source_dir)
click to toggle source
# File lib/mygen/files.rb, line 3 def template_files(path = template_source_dir) Dir.glob(File.join(path, "**/*")).select { |f| File.file? f } end
Private Instance Methods
replaced_filename(file, bindings)
click to toggle source
# File lib/mygen/files.rb, line 49 def replaced_filename(file, bindings) elements = File.basename(file).split('.') elements.pop if elements.last == 'erb' dirname = File.dirname(file) f = elements.map do |element| element.start_with?('__') ? eval( element.sub(/^__/, ''), bindings) : element end.join('.') File.join(dirname, f) end