Sha256: 84cc880fb82075be62432189a3d7ae0b2e79a21468f1b1405aef0f769bada688

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

module Dextery
  module Generator
    def self.manifest(args, options = {})
      raise ArgumentError.new("You must specify a path") if args.empty?

      new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
      if preserve_source_location?(new_blog_path, options)
        Dextery.logger.error "Conflict: #{new_blog_path} exists and is not empty."
      else
        clean_directory(new_blog_path) if options[:force]
        copy_bootstrap(new_blog_path)
        notify_success
      end
    end

    private
    def self.preserve_source_location?(path, options)
      !options[:force] && !Dir["#{path}/**/*"].empty?
    end

    def self.clean_directory(path)
      Dextery.logger.info "Cleanup directory #{path}.. Start"
      system("rm -rf #{path}")
      Dextery.logger.info "Cleanup directory #{path}.. Complete"
    end

    def self.copy_bootstrap(path)
      template_path = File.join(File.expand_path('..', __FILE__), 'template', '/')
      Dextery.logger.info "Setup blog using bootstrap.. Start"
      system( "cp -r #{template_path} #{path}")
      Dextery.logger.info "Setup blog using bootstrap.. Complete"
    end

    def self.notify_success
      # We can do something really cool here,
      # something like ASCII art, for now let's just
      # log it.
      Dextery.logger.info "I am a very neat monster"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dextery-0.0.4a lib/dextery/generator.rb
dextery-0.0.4 lib/dextery/generator.rb