lib/tap/generator/generate.rb in tap-gen-0.3.1 vs lib/tap/generator/generate.rb in tap-gen-0.7.0

- old
+ new

@@ -1,21 +1,31 @@ require 'tempfile' +require 'tap/generator/base' module Tap module Generator - # :startdoc::module A mixin defining how to run manifest actions. + # ::mixin run generators + # + # A mixin defining how to run manifest actions. module Generate + extend Lazydoc::Attributes + lazy_attr(:desc, 'mixin') + def self.parse(argv=ARGV, app=Tap::App.current, &block) + Base.parse_as(self, argv, app, &block) + end + # Creates the target directory if it doesn't exist. When pretend is # true, creation is logged but does not actually happen. # # No options currently affect the behavior of this method. def directory(target, options={}) - target = File.expand_path(target) + target = path(target) case + when target == Dir.pwd when File.exists?(target) log_relative :exists, target else log_relative :create, target FileUtils.mkdir_p(target) unless pretend @@ -35,11 +45,11 @@ source_file = Tempfile.new('generate') yield(source_file) if block_given? source_file.close source = source_file.path - target = File.expand_path(target) + target = path(target) copy_file = true msg = case when !File.exists?(target) :create @@ -65,20 +75,26 @@ # Returns :generate def action :generate end + def to_spec + spec = super + spec['mixin'] = 'Tap::Generator::Generate' + spec + end + protected # Ask the user interactively whether to force collision. def force_file_collision?(target) return false if skip return true if force prompt_out.print "overwrite #{target}? [Ynaiq] " prompt_out.flush case prompt_in.gets.strip - when /^y(es)?$/i + when /^y(es)?$/i, '' true when /^n(o)?$/i false when /^a(ll)?$/i self.force = true