Sha256: da2bab4e7661698723a8d46123c5d7d3726b9fe91dab1fd1a44e39e3ff908643

Contents?: true

Size: 1.34 KB

Versions: 11

Compression:

Stored size: 1.34 KB

Contents

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

    def initialize
      super
      @children = []
      @generators = []
    end

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

    def destroy
      unexecute_generators
      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

    def execute_generators
      generators.each do |generator|
        generator.execute
      end
    end

    def unexecute_generators
      generators.each do |generator|
        generator.unexecute
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sprout-1.1.18.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.17.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.16.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.15.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.14.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.13.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.11.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.10.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.7.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.5.pre lib/sprout/generator/directory_manifest.rb
sprout-1.1.4.pre lib/sprout/generator/directory_manifest.rb