Class: Rupat
Overview
Rupat
Introduction
Rupat is a Ruby Patching utility. It can be used to patch files or for extracting information from files.
Rupat includes:
- RupatMod
-
File content manipulation methods.
- Rupat
-
Class methods for Rupat script creation.
- Rupat command
-
Shell command for creating Rupat patch files.
Typical Rupat script opens a file for editing, uses Regexp searches to find the file position(s) to change, and adds/replaces the content. File positions can be referred also line numbers.
Rupat command can be used to create a patch script from diff output. The generated script includes RupatMod commands which implement the transformation.
Rupat includes lines of the file in a line Array. Rupat keeps track of the current line. Many editing commands use the current line to specify the context for editing.
Rupat has two parts: Rupat class and RupatMod. Rupat class is a front end class to create Rupat instance for editing. Rupat includes RupatMod. RupatMod can be used for other user classes that benefit from lines editing.
The basic flow is:
- open file
-
Source file can be opened in multiple editing modes.
- line manipulation
-
Search/jump to lines, extract and edit content (See: RupatMod for all access/editing methods).
- save file
-
Save the editing results to the source file or to a newly created file.
Rupat class
Rupat is a class that provides the default entry point to the RupatMod module.
The user can modify, duplicate, or just read file(s).
- update
-
Perform content update for a file, but without any backups.
- edit
-
Inplace editing with possibility to backup the original.
- open
-
Open file in read-only mode. Possibility to save the changes later exist.
- create
-
A named file is to be created from source file.
Example usage:
# Open file for reading.
r = Rupat.update( "report.txt" )
# Find line.
r.find /cpp/
# Collect some lines.
line = r.line
data = 4.times.collect do |i|
r.get( line + i )
end
# Duplicate the lines collected.
insertMany( data )
# Save changes.
r.close
Rupat command
Rupat command is a simple shell command using Rupat. Main purpose is to execute Rupat programs. It can also be used to generate a Rupat patch from files with different content. When applied, the patch transforms file1 to file2.
Constant Summary
- VERSION =
"0.0.4"
Instance Attribute Summary
Attributes included from RupatMod
#copybuf, #lines, #newFile, #orgFile
Class Method Summary (collapse)
-
+ (Object) create(orgFile, newFile)
Create new file based on old file.
-
+ (Object) edit(file, backup = true)
Edit existing file and by default make backup.
-
+ (Object) lines(lines)
Use set of lines for editing.
-
+ (Object) open(file)
Open existing file for reading.
-
+ (Object) readonly(file)
Open existing file for reading.
-
+ (Object) update(file)
Edit existing file inplace without backups.
- + (Object) version
Instance Method Summary (collapse)
-
- (Object) useAlias
Use short aliases from RupatAlias module.
Methods included from RupatMod
#[], #abort, #append, #appendMany, #backward, #close, #copy, #create, #cut, #delete, #deleteMany, #edit, #excursion, #findBackward, #findBackward?, #findBlock, #findForward, #findForward?, #forward, #get, #getMany, #goto, #goto1, #gotoEnd, #gotoFirst, #gotoForce, #gotoLast, #insert, #insertFile, #insertMany, #last, #length, #line, #line1, #next, #open, #paste, #prev, #print, #replace, #replaceAll, #replaceWithin, #save, #set, #update, #use
Class Method Details
+ (Object) create(orgFile, newFile)
Create new file based on old file.
893 894 895 896 897 |
# File 'lib/rupat.rb', line 893 def Rupat.create( orgFile, newFile ) r = Rupat.new r.create( orgFile, newFile ) r end |
+ (Object) edit(file, backup = true)
Edit existing file and by default make backup.
882 883 884 885 886 |
# File 'lib/rupat.rb', line 882 def Rupat.edit( file, backup = true ) r = Rupat.new r.edit( file, backup ) r end |
+ (Object) lines(lines)
Use set of lines for editing.
903 904 905 906 907 |
# File 'lib/rupat.rb', line 903 def Rupat.lines( lines ) r = Rupat.new r.use( lines ) r end |
+ (Object) open(file)
Open existing file for reading.
862 863 864 865 866 |
# File 'lib/rupat.rb', line 862 def Rupat.open( file ) r = Rupat.new r.open( file ) r end |
+ (Object) readonly(file)
Open existing file for reading.
872 873 874 |
# File 'lib/rupat.rb', line 872 def Rupat.readonly( file ) Rupat.open( file ) end |
+ (Object) update(file)
Edit existing file inplace without backups.
854 855 856 |
# File 'lib/rupat.rb', line 854 def Rupat.update( file ) Rupat.edit( file, false ) end |
+ (Object) version
3 4 5 |
# File 'lib/version.rb', line 3 def Rupat.version Rupat::VERSION end |
Instance Method Details
- (Object) useAlias
Use short aliases from RupatAlias module.
911 912 913 914 |
# File 'lib/rupat.rb', line 911 def useAlias Rupat.send( :include, RupatAlias ) self end |