Sha256: bf2712bdab5d6ebe364322110189a8404814f865babd7dc201c2bb322af20a39

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 KB

Contents

module ApplicationView
  module FileSupport
    def confirm_overwrite(path)
      if File.exists?(path)
        puts "File exists: #{display_path(path)}"
        print "  overwrite? (y/n)"
        answer = $stdin.gets
        
        answer =~ /^y/i
      else
        true
      end          
    end
    
    # friendlier display of paths
    def display_path(path)
      path = File.expand_path(path)
      path.gsub(BASE_PATH, "")
    end
    
    # saves the output string to the filename given
    #
    def save_to_file(output, filename)
      unless File.exists?(filename)      
        File.open(filename, "w") do |w|
          w.write(output)
        end
      end
    end
  
    # given a path and line number, returns the line and two lines previous
    #
    def get_line_from_file(path, line_number)
      line_number = line_number.to_i
      output = ""
      lines = []
    
      File.open(path) do |f|
        lines = f.readlines
      end
  
      output += "\n"
  
      3.times do |i|
        line = lines[line_number-(3-i)]
        output += line if line
      end
  
      output += "\n"      
    
      output
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ymdp-0.0.17 lib/application_view/support/file.rb
ymdp-0.0.16 lib/application_view/support/file.rb
ymdp-0.0.15 lib/application_view/support/file.rb
ymdp-0.0.14 lib/application_view/support/file.rb
ymdp-0.0.13 lib/application_view/support/file.rb
ymdp-0.0.12 lib/application_view/support/file.rb
ymdp-0.0.11 lib/application_view/support/file.rb
ymdp-0.0.10 lib/application_view/support/file.rb
ymdp-0.0.9 lib/application_view/support/file.rb
ymdp-0.0.8 lib/application_view/support/file.rb
ymdp-0.0.7 lib/application_view/support/file.rb
ymdp-0.0.6 lib/application_view/support/file.rb
ymdp-0.0.5 lib/application_view/support/file.rb
ymdp-0.0.4 lib/application_view/support/file.rb
ymdp-0.0.3 lib/application_view/support/file.rb