instance method file

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

file(relative_source, relative_destination, file_options = {})

Remove a file if it exists and is a file.

Parameters

relative_source req
relative_destination req
file_options opt = {}
Source
# File railties/lib/rails_generator/commands.rb, line 431
        def file(relative_source, relative_destination, file_options = {})
          destination = destination_path(relative_destination)
          if File.exist?(destination)
            logger.rm relative_destination
            unless options[:pretend]
              if options[:svn]
                # If the file has been marked to be added
                # but has not yet been checked in, revert and delete
                if options[:svn][relative_destination]
                  system("svn revert #{destination}")
                  FileUtils.rm(destination)
                else
                # If the directory is not in the status list, it
                # has no modifications so we can simply remove it
                  system("svn rm #{destination}")
                end
              elsif options[:git]
                if options[:git][:new][relative_destination]
                  # file has been added, but not committed
                  system("git reset HEAD #{relative_destination}")
                  FileUtils.rm(destination)
                elsif options[:git][:modified][relative_destination]
                  # file is committed and modified
                  system("git rm -f #{relative_destination}")
                else
                  # If the directory is not in the status list, it
                  # has no modifications so we can simply remove it
                  system("git rm #{relative_destination}")
                end
              else
                FileUtils.rm(destination)
              end
            end
          else
            logger.missing relative_destination
            return
          end
        end

Defined in railties/lib/rails_generator/commands.rb line 431 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Rails::Generator::Commands::Destroy

Type at least 2 characters to search.

↑↓ navigate · open · esc close