Module: Mygen::Files
- Included in:
- Generator
- Defined in:
- lib/mygen/files.rb
Instance Method Summary collapse
- #directory_exists?(path) ⇒ Boolean
- #file_destination(file, bindings) ⇒ Object
- #internal_template_files ⇒ Object
- #internal_template_source_dir ⇒ Object
- #move_file_in_place(src, dest) ⇒ Object
- #template_dirs(path = template_source_dir) ⇒ Object
- #template_files(path = template_source_dir) ⇒ Object
Instance Method Details
#directory_exists?(path) ⇒ Boolean
43 44 45 |
# File 'lib/mygen/files.rb', line 43 def directory_exists?(path) File.directory?(path) && File.exist?(path) end |
#file_destination(file, bindings) ⇒ Object
19 20 21 22 23 |
# 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 ⇒ Object
11 12 13 |
# File 'lib/mygen/files.rb', line 11 def internal_template_files template_files(internal_template_source_dir) end |
#internal_template_source_dir ⇒ Object
15 16 17 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
7 8 9 |
# 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) ⇒ Object
3 4 5 |
# 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 |