Sha256: d9031479dc3f7b78124709b76f11d53a520c3c3467dba1970a29b22dd24ccec6

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

require 'fileutils'

class Gator
  module Scaffolding
    class ScaffoldingFileUtils
      include Thor::Actions

      def scaffolds_home
        File.join(Gator::Paths.gator_home, "scaffolds")
      end

      def scaffold_directory name
        File.join(scaffolds_home, name)
      end

      def directory_entries dir, join= true
        entries = Dir.entries dir
        entries.delete(".")
        entries.delete("..")
        entries.collect! { |e| File.join(dir, e) } if join
        entries
      end

      def last_directory_name dir
        dir.split(File::PATH_SEPARATOR).last
      end

      def scaffold_entries join= false
        directory_entries scaffolds_home, join
      end

      def create_empty_directory_files dir
        Dir.glob(File.join(dir, "**", "*")).each { |f|
          create_file File.join(f, ".empty_directory"), ".empty_directory" if File.directory?(f) && Dir.entries(f).length == 2
        }
      end

      def install_scaffold from_dir, name=nil
        name ||= last_directory_name from_dir
        entries = directory_entries from_dir
        install_dir = scaffold_directory(name)
        #empty_directory install_dir
        FileUtils.mkdir_p install_dir
        FileUtils.cp_r entries, install_dir
        create_empty_directory_files install_dir
      end

      def delete_scaffold name
        FileUtils.rm_r scaffold_directory(name)
      end

      def delete_all_scaffolds
        scaffold_entries.each { |scaffold| delete_scaffold(scaffold) }
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gator-0.0.24.pre lib/gator/plugins/scaffolding/scaffolding_file_utils.rb
gator-0.0.23.pre lib/gator/plugins/scaffolding/scaffolding_file_utils.rb
gator-0.0.22.pre lib/gator/plugins/scaffolding/scaffolding_file_utils.rb