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 collapse
- VERSION =
"0.0.2"
Instance Attribute Summary
Attributes included from RupatMod
#copybuf, #lines, #newFile, #orgFile
Class Method Summary collapse
-
.create(orgFile, newFile) ⇒ Object
Create new file based on old file.
-
.edit(file, backup = true) ⇒ Object
Edit existing file and by default make backup.
-
.lines(lines) ⇒ Object
Use set of lines for editing.
-
.open(file) ⇒ Object
Open existing file for reading.
-
.readonly(file) ⇒ Object
Open existing file for reading.
-
.update(file) ⇒ Object
Edit existing file inplace without backups.
- .version ⇒ Object
Instance Method Summary collapse
-
#useAlias ⇒ Object
Use short aliases from RupatAlias module.
Methods included from RupatMod
#[], #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
.create(orgFile, newFile) ⇒ Object
Create new file based on old file.
887 888 889 890 891 |
# File 'lib/rupat.rb', line 887 def Rupat.create( orgFile, newFile ) r = Rupat.new r.create( orgFile, newFile ) r end |
.edit(file, backup = true) ⇒ Object
Edit existing file and by default make backup.
876 877 878 879 880 |
# File 'lib/rupat.rb', line 876 def Rupat.edit( file, backup = true ) r = Rupat.new r.edit( file, backup ) r end |
.lines(lines) ⇒ Object
Use set of lines for editing.
897 898 899 900 901 |
# File 'lib/rupat.rb', line 897 def Rupat.lines( lines ) r = Rupat.new r.use( lines ) r end |
.open(file) ⇒ Object
Open existing file for reading.
856 857 858 859 860 |
# File 'lib/rupat.rb', line 856 def Rupat.open( file ) r = Rupat.new r.open( file ) r end |
.readonly(file) ⇒ Object
Open existing file for reading.
866 867 868 |
# File 'lib/rupat.rb', line 866 def Rupat.readonly( file ) Rupat.open( file ) end |
Instance Method Details
#useAlias ⇒ Object
Use short aliases from RupatAlias module.
905 906 907 908 |
# File 'lib/rupat.rb', line 905 def useAlias Rupat.send( :include, RupatAlias ) self end |