Sha256: 8b0b3984448071c16954c8a7889f215450c385da4f303dd205dbcdb548408cf2

Contents?: true

Size: 1002 Bytes

Versions: 17

Compression:

Stored size: 1002 Bytes

Contents

module Sprout::Generator
  class DirectoryManifest < Manifest
    attr_reader :children

    def initialize
      super
      @children = []
    end

    def create
      if !File.directory?(path)
        FileUtils.mkdir_p path
        say "Created directory: #{path}"
      else
        say "Skipped existing:  #{path}"
      end
      create_children
    end

    def destroy
      success = destroy_children

      if success && can_remove?
        FileUtils.rmdir path
        say "Removed directory: #{path}"
        true
      else
        say "Skipped remove directory: #{path}"
        false
      end
    end

    private

    def can_remove?
      File.directory?(path) && Dir.empty?(path)
    end

    def create_children
      created = children.select { |child| child.create }
      return (created.size == children.size)
    end

    def destroy_children
      destroyed = children.reverse.select { |child| child.destroy }
      return (destroyed.size == children.size)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
sprout-1.0.20.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.19.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.18.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.17.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.16.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.15.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.14.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.13.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.11.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.9.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.8.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.5.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.4.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.3.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.2.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.1.pre lib/sprout/generator/directory_manifest.rb
sprout-1.0.0.pre lib/sprout/generator/directory_manifest.rb