Module: Antwort::FileHelpers
- Included in:
- Build, Builder, CLI, CLI::Upload, EmailCollection, EmailTemplate
- Defined in:
- lib/antwort/helpers/file_helper.rb
Instance Method Summary collapse
- #count_files(dir) ⇒ Object
- #create_file!(opts) ⇒ Object
- #email_id_from_folder_name(name) ⇒ Object
- #list_folders(folder_name) ⇒ Object
Instance Method Details
#count_files(dir) ⇒ Object
3 4 5 |
# File 'lib/antwort/helpers/file_helper.rb', line 3 def count_files(dir) Dir[File.join(dir, '**', '*')].count { |f| File.file? f } end |
#create_file!(opts) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/antwort/helpers/file_helper.rb', line 16 def create_file!(opts) path = opts[:path] content = opts[:content] file = File.new(path, 'w') file.write(content) file.close say ' create ', :green say path.gsub(%r{\A./}, '') file end |
#email_id_from_folder_name(name) ⇒ Object
12 13 14 |
# File 'lib/antwort/helpers/file_helper.rb', line 12 def email_id_from_folder_name(name) name.split('-')[0..-2].join('-') end |
#list_folders(folder_name) ⇒ Object
7 8 9 10 |
# File 'lib/antwort/helpers/file_helper.rb', line 7 def list_folders(folder_name) path = File.(folder_name) Dir.entries(path).select { |f| !f.include? '.' } end |