Sha256: 778c8b72264d5613fe273b7bb2c7b73bdcf84dd5731e2aeb93c6f2db2954de83

Contents?: true

Size: 1.61 KB

Versions: 6

Compression:

Stored size: 1.61 KB

Contents

module Tap
  module Generator 
    module Generate
      def iterate(actions)
        actions.each {|action| yield(action) }
      end
  
      def directory(target, options={})
        target = File.expand_path(target, target_dir)
        
        if File.exists?(target)
          log_relative :exists, target
        else
          log_relative :create, target
          file_task.mkdir(target) unless pretend
        end
      end
    
      def file(target, options={})
        target = File.expand_path(target, target_dir)
        
        case
        when !File.exists?(target)
          log_relative :create, target
          # should check for identical...
        when force_file_collision?(target)
          log_relative :force, target
        else
          log_relative :skip, target
          return
        end
        
        unless pretend
          file_task.prepare(target) 
          File.open(target, "wb") {|file| yield(file) if block_given? }
        end
      end
      
      # Ask the user interactively whether to force collision.
      def force_file_collision?(target)
        return false if skip
        return true if force
        
        $stdout.print "overwrite #{target}? [Ynaiq] "
        $stdout.flush
        case $stdin.gets
        when /a/i
          self.force = true
        when /i/i
          self.skip = true
        when /q/i
          $stdout.puts "aborting #{name}"
          raise SystemExit
        when /n/i then false
        when /y/i then true
        else force_file_collision?(destination)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
bahuvrihi-tap-0.10.0 lib/tap/generator/generate.rb
bahuvrihi-tap-0.10.1 lib/tap/generator/generate.rb
bahuvrihi-tap-0.10.2 lib/tap/generator/generate.rb
bahuvrihi-tap-0.10.3 lib/tap/generator/generate.rb
tap-0.10.0 lib/tap/generator/generate.rb
tap-0.10.1 lib/tap/generator/generate.rb