Method: ActiveFacts::Generators::Rails::Models#create_if_ok

Defined in:
lib/activefacts/generators/rails/models.rb

#create_if_ok(filename) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/activefacts/generators/rails/models.rb', line 105

def create_if_ok filename
  # Create a file in the output directory, being careful not to overwrite carelessly
  if @output
    pathname = (@output+'/'+filename).gsub(%r{//+}, '/')
    @preexisting_files.reject!{|f| f == pathname }    # Don't clean up this file
    if generated_file_exists(pathname) == false
      $stderr.puts "not overwriting non-generated file #{pathname}"
      @individual_file = nil
      return
    end
    @individual_file = @out = File.open(pathname, 'w')
    puts "#{HEADER}"
  end
  true
end